المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : حل مشكلة Uncaught mysqli_sql_exception: Incorrect integer value: '' for column 'id'



Rise Company
09-12-2023, 03:02
حل مشكلة Uncaught mysqli_sql_exception: Incorrect integer value: '' for column 'id'
Incorrect integer value: '' for column 'id' at row 1 -File upload in PHP giving error
[RESOLVED] MySQL error : "Incorrect integer value" for column id at row 1
Sorry, file already exists.Sorry, your file was not uploaded.Sorry, file already exists.Sorry, your file was not uploaded.
How to disable MySQL Strict Mode
Critical: MySQL enables "strict mode" by default as of version 5.7. Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. Applications not built with strict mode enabled may cause undesired behavior; please verify applications using MySQL are compatible before upgrading. More information about strict mode is available here.
Is it possible to change Strict Mode for a single user or database?

https://www.rise.company/upload/uploads/170208566396871.png

المشكلة :

يوجد عميل لديه برمجية خاصة php تعمل بدون مشاكل مع استضافة اخري
لكن معنا لا تعمل رغم تجربة 3 سيرفرات اخرى جميعها نفس المشكلة

البرمجة كاملة تعمل بشكل سليم عدا خاصية واحدة وهى اضافة تلاميز داخل قاعدة بيانات
اى انه المشكلة فى ادخال بيانات فتظهر مشكلة فى الرفع


Sorry, file already exists.Sorry, your file was not uploaded.Sorry, file already exists.Sorry, your file was not uploaded.

ليست مشكلة اصدار MY SQL ولا نوع MYSQL ام Mariadb
ولكن الشىء المختلف عندنا ان لدينا cpanel اما العميل كان على لوحة اخري غير cpanel

سبب المشكلة :

هناك بعض التطبيقات غير متوافقه مع بعض اعدادات SQL

وبعد فحص قاعدة البيانات والوصل الى السطر الخطا الذى به المشكلة وهو بهذا الشكل



Incorrect integer value: ‘ ‘ for column ‘a_column_name’ at row 1


هنجد المشكلة فى قيمة فارغة ‘ ‘لا تقبلها mysql لتجنب sql injections

This is just an example to show you how will you get the MySQL error further. Let me explain in code concept: If the string value is assigned to PHP script, that too the empty string is assigned meanly then you will get the error code Incorrect integer value….

Behind this scenario, the script which is running tries to update or insert the row with the entry integer may be with values assigning it as default ( 0 or Null, AUTO_INCREMENT) value.

Due to STRICT mode, MySQL doesn’t disturb this action and so the reason would be SQL_MODE.


To ensure compatibility with your applications,
you may need to change the SQL configuration.


https://www.rise.company/upload/uploads/17020824577941.png

حل المشكلة :

يوجد فى cpanel مشكلة لا توجد عند غيرها !
حيث ان العميل كان على hostinger وعمل معه بدون مشكل
فاتضح لنا ان المشكلة فى cpanel التى بها قيم Default غير موجودة
على غيرها من لوح التحكم المختلفة وحلها هى :

ادخل على WHM ثم Edit SQL Configuration

In cPanel v102, we added the "SQL Configuration" interface, allowing you to adjust many common MySQL values. To access this interface, log into WHM, then navigate to "SQL Configuration" using the search bar.

هتجد داخل SQL MODE


ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_ DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_EN GINE_SUBSTITUTION

احذف STRICT_TRANS_TABLES وهتجد ان المشكلة تم حلها
لا تنسى عمل ريستارت لقاعدة البيانات

-----------------------------

ما هو STRICT_TRANS_TABLES وما وظيفته ؟

https://www.rise.company/forum/images/imported/2023/12/8.png

MySQL Strict Mode controls how invalid or missing values in data changing queries are handled. This includes INSERT, UPDATE and CREATE TABLE statements. With MySQL Strict Mode enabled, which is the default state, invalid or missing data may cause warnings or errors when attempting to process the query.
When Strict Mode is disabled, the same query would have its invalid or missing values adjusted and would produce a simple warning. This may seem like the preferred result; however, with Strict Mode disabled, specific actions may cause unexpected results. For instance, when the value being inserted exceeds the maximum character limit, it is truncated to fit the limit.

-----------------------------


هل يمكن تعديل MYSQL على user واحد فقط دون العمل على السيرفر كامل ؟
Is it possible to change Strict Mode for a single user or database

لا يمكن عمل التعديل على يوزر واحد فقط

It is technically possible to change the sql_mode on a per session basis, meaning that the sql_mode would only be customized for the duration that the client has logged into the database. Modifying the sql_mode on a per session basis is not advisable or practical except for advanced applications where the systems administrator or developer implementing this type of usage is well versed in database administration.

Changing the sql_mode should generally be done on a server-wide basis to avoid complications and difficult to resolve problems. The method to modify the sql_mode server-wide is outlined in the below procedure.

-----------------------------

هل هو امن تعطيل disable MySQL strict mode على مستوى السيرفر ؟
it a good idea to disable MySQL strict mode on the server?

Yes! Because many customers are facing with errors like “Field '' doesn't have a default value” while managing some applications. The root cause of this error is that some software applications like WHMCS do not require MySQL strict mode to be enabled on the server.

-----------------------------

ملحوظة :
هذا الحل على مستوى السيرفر لذلك يفضل ان العميل يحل المشكلة الخاصة به
فى طريقة التعامل مع قاعدة البينات وليس تعديلها على السيرفر
ولكن لا مشكلة اطلاقا فى تعطيلها واغلب الشركات بتفتحها.

المرجع:
https://hoststud.com/resources/resolved-mysql-error-incorrect-integer-value-for-column-id-at-row-1.493/
https://support.cpanel.net/hc/en-us/articles/360051769294-How-to-edit-the-MySQL-MariaDB-configuration-my-cnf-file
https://stackoverflow.com/questions/14762904/incorrect-integer-value-for-column-id-at-row-1
https://board.phpbuilder.com/d/10403765-mysqli-sql-exception-incorrect-integer-value-functionphp/2
https://support.cpanel.net/hc/en-us/articles/360060133213-How-to-disable-MySQL-Strict-Mode-
https://bobcares.com/blog/mysql-disable-strict-mode/