Different PDO behaviours between PHP versions

I have three servers running as my development, staging and production servers. The PHP version running are: 5.5.23, 5.5.9, 5.5.20 respectively.

They are running exactly the same code. But my development server was throwing exceptions whereas the other two works fine. The exception is follow:

Error: [PDOException] SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'comment_id' at row 1
Request URL: /comments/add.json Stack Trace: 0 /Users/me/Sites/MySite/lib/Cake/Model/Datasource/DboSource.php(460): PDOStatement->execute(Array)1
1 /Users/me/Sites/MySite/lib/Cake/Model/Datasource/DboSource.php(426): DboSource->_execute('INSERT INTO `po...', Array)1
2 /Users/me/Sites/MySite/lib/Cake/Model/Datasource/DboSource.php(1008): DboSource->execute('INSERT INTO `po...')1
3 /Users/me/Sites/MySite/lib/Cake/Model/Model.php(1744): DboSource->create(Object(Notification), Array, Array)1
4 /Users/me/Sites/MySite/app/Controller/CommentsController.php(181): Model->save(Array)1
5 [internal function]: CommentsController->add()

The value being inserted is a bool(false) while the database is expecting integers. So I had to do something like to handle this issue for my development server:

//The comment id is set to false. Needs to turn it to NULL as DB can't handle false for integer if($this->Comment->id === false) $notification['Notification']['comment_id'] = NULL; else $notification['Notification']['comment_id'] = $this->Comment->id;

My question is: Why my staging and production server can handle this issue (auto-convert the false value into integer, possibly), but my development server cannot?

As you can see, my servers are running CakePHP. I have been looking at the PDO versions but it seemed like it doesn't give me too much insight. My development server is running on my Mac Book Mac OS X 10.10. The staging and production are running Ubuntu 12.04.

-------------Problems Reply------------

You most likely have strict mode for MySQL disabled on your Production and Staging environments, while your development environment has this enabled.

See more here:

Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.)

If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings

You can read on how to change this mode here.

On OS X, the following link has more details:

After a lot of poking around I found out that MySQL for OS X from Oracle ships with a /usr/local/mysql/my.cnf which is loaded on startup. In this file is a sole configuration directive for sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES. Once I commented this out and restarted the server strict mode was off, my ORM worked and I was happy.

Category:php Views:6 Time:2018-03-11
Tags: php mysql pdo

Related post

  • Different struct types between system versions. This is a stumper 2012-02-01

    I'm working on an iPhone tweak where I need to read from and modify the contents of a struct. However, the struct definition is different between iOS 4.1, iOS 4.2, and iOS 5, and I would like to retain compatibility with all of these. The problem is

  • Different browser behaviour between localStorage/sessionStorage and cookies 2010-12-13

    This is not so much a technical question as a question of practice: browser storage doesn't seem to have the same browser behaviour as cookies. For example: In Firefox 3.6, sessionStorage is not shared between tabs within the same browser session. lo

  • Your PHP MySQL library version differs from your MySQL server version 2010-03-01

    I've recently upgraded MySQL on my Debian 5.0.4 server to 5.1. Now phpMyAdmin shows the following warning: Your PHP MySQL library version 5.0.51a differs from your MySQL server version 5.1.43 Is it likely to cause any problems? --------------Solution

  • different sha1 checksum on different php versions? 2010-07-02

    I run this script: define('SECRET', "vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5"); echo sha1(SECRET . 'zcbkeyky' . '[email protected]') . "\n"; Locally with PHP 5.3.2 (cli) it gives me: 3baa47e50394cd2dce236dcbf2f409fdb9010f2a On a remote machine with PHP 5.1.6 (cli)

  • How to configure local web server such that it should switch between one php version to another 2010-08-27

    I'm developing one web application, using PHP eclipse IDE. For an instance i want to switch from one PHP version to another version which resides in different location. Below is my working environment : 1) Having Centos OS 2) PHP 5.1.6 have installed

  • PHP: same code, same PHP version, same database, same machine- different results with foreach and reference 2011-01-18

    I'm iterating through an array using foreach, like this: foreach ($x as &$y) { .... modify $y .... } I've very thoroughly debugged this code on my home machine, and it works great on the testbed site. On the production site on the same machine wi

  • $GLOBALS variable in different php version 2012-02-28

    In php version 5.2.17,I used $GLOBALS variable to get some information and it's work good. but when I change php version(5.3) that this variable get value missed sometime.so i don't know the reason? --------------Solutions------------- http://php.net

  • Different php versions in VPS for every account. How? 2012-04-07

    i have a virtual dedicated server: PHP version 5.3.1 PHP Handler : suphp What i need is to have different php versions (5.2.17) in some of my accounts. Is this possible to be done and how can i do this? Thank you in advance --------------Solutions---

  • whats the different between vista versions? 2012-11-08

    whats the different between vista versions? --------------Solutions------------- http://www.microsoft.com/windows/windows-vista/compare-editions/default.aspx "Compare Windows Vista editions" The above MS link lists the different Features in each Vist

  • Laravel migration and model data store on different PHP versions drops error 2014-09-26

    I have some problems with the same code on different php version. I have created my migration as it follows Schema::create('reports', function(Blueprint $table) { $table->engine = 'InnoDB'; $table->integer('affiliate_id')->unique(); $table-

  • different behaviour between ipython and python shell for importing paraview 2014-12-01

    I'm trying to use paraview (http://www.paraview.org/) with python scripting in ipython. When I'm trying to use it in a python shell it works just find but when I'm trying in ipython I've got the following error: >>> import paraview.simple Tr

  • Lost between 2 version of PHP running on the same environement 2010-11-10

    Typing on the console gives me : php -v : 5.3.2 PHP 5.3.2 (cli) (built: Oct 13 2010 13:09:53) mysql.sock : /Applications/MAMP/tmp/mysql/mysql.sock It's the version installed with MAMP (which i've just uninstalled) If i do a phpinfo() on a browser PHP

  • PHP version causes different behavior of skipping lines for the same code 2012-02-04

    while($c=fgets(STDIN)){ if($c===PHP_EOL){ continue; } else { echo $c; } } When the above code is called from the command line in php 5.3.8, it prints the rows in the input file, and skips any empty lines. However, in php 5.2.6, it does not skip over

  • Is there an output difference between php 4 and 5? 2009-12-20

    I noticed the other day that a new script I wrote for php 5 began outputting html that was viewable before the php script had actually finished. Did this happen with 4? For instance, I have a long loop that echos something out with each iteration. Th

  • Difference between IE6 versions 2009-08-05

    Whats the difference between version 6.00.2800 and 6.00.2900 of Internet Explorer 6? Can anyone confirm different CSS rendering between IE6 SP1, SP2, SP3 ? Should I browser test my pages across different Service Packs? --------------Solutions--------

  • What are the differences between php 4 and php 5? 2010-06-30

    I have some code that gets a wordpress rss feed and displays the news articles on my own website. This code works fine on my development server that is running php 5.3.1 but when I upload it to my live website that only has php 4.4.9 I am getting lot

  • Which PHP version is currently running 5.2.15 or 5.3.4? 2010-12-14

    i often read official PHP website website. on 9 Dec,2010 headlines was PHP 5.2.15 Released! and on 10 Dec,2010 headlines was PHP 5.3.4 Released! i m really confused that what means of two different headlines?? i think version order are may b wrong or

  • error with PDO connection in php 2011-02-09

    i have PHP Version 5.2.8 on my windows 2003 server, i am trying to connect with database $dbh = new PDO("mysql:host=localhost;port=3306;dbname=$db_name", $db_user, $db_pass); but when i use this statement i got following error Fatal error: Uncaught e

  • Single quotes reversing behaviour in PHP 2011-05-25

    I was running over a sample script and hit on this particular issue. The script starts off by setting $docroot=$_SERVER['DOCUMENT_ROOT']; For writing to a file, @$fp = fopen("$docroot/../parts/partsorders.txt",'ab'); is used. But no matter what, this

  • Is it possible to determine which php version is most widely used on paid webhosting services? 2009-08-28

    I'm assuming every modern hosting provider gives access to php5 (and i noticed that many have both 4 and 5) but now WHICH php5 is most popular... let's say i'm trying to choose between curl copy handle and curl setopt array (in my previous question).

  • PCI Compliance + Magento + PHP version 2009-12-03

    I'm trying to get PCI Compliance for my dedicated server (Red Hat Enterprise Linux), which is running Magento. When I first installed Magento on the server, I realized that RHEL comes with a PHP version which is too old for Magento (5.1.6). So, I fou

  • PHP versions "market share" 2010-02-26

    Does anyone know where can I find recent data on PHP4 vs PHP5 "market share", that is, what percentage of servers on the Internet have PHP5 installed? I found this but it's from 2008: http://www.nexen.net/chiffres_cles/phpversion/18824-php_statistics

  • TabHost color changed between Android versions 2010-10-04

    i've noticed that the default look of tabs has changed between Android versions (see screenshot). I like the first version better, but i need to set my android target to version 8 (android 2.2) so that app2sd works. but then i have the darker backgro

  • Downgrading PHP version on Drupal Test Server 2010-10-29

    I have several live Drupal sites running on an Ubuntu server (10.04), Apache 2.2 with PHP 5.2.3-1. I recently started the work of setting up a test server that would be as close as possible to the live environment, but I stupidly didn't check the PHP

  • Difference between two versions in ClearCase dynamic view 2010-12-02

    Say , I've two different dynamic views in ClearCase. I would like to know if there is any command to give a report with: "x lines added , y lines deleted , z lines changed" between two versions. --------------Solutions------------- Yes, you can use d

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.089 (s). 11 q(s)