SecretCoder SecretCoder -3 years ago 52
MySQL Question

Baffling MySQL-PHP insert is working 100% in one machine but 50% on another

I am using PHP to parse an XML file and insert it into 2 MySQL tables (the tables are on the same MySQL database). The baffling problem is that I have the same PHP script working on a virtual machine and it is working great, it inserts into the 2 tables all the data correctly. However, in another virtual machine (Both have Ubuntu Server 16.04 and the same configuration in Apache, PHP - I ran diff against the configs to validate it), it only inserts the data on the first table and in the second table is not inserting data. How could this be if both scripts are the same version and the OS and configurations are the same?

Kind regards and thanks for your time.

Answer Source

I found the error, it happens that on the virtual machine that the script was working I have installed PHP 7.0 and on the virtual machine where the script wasn't working I have PHP 7.1, it looks that PDO in 7.1 is a lot stricter and I wasn't seeing all the errors because I was missing: $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); to see all the exceptions in PHP 7.1. When I added that line to my script I saw this error: PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect decimal value: '' for column from there it was very easy to fix it. I hope that this helps to someone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download