Null is replaced with 0 when inserting int values in MySQL

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
al_anchorite

Null is replaced with 0 when inserting int values in MySQL

Post by al_anchorite »

Hi! I'm running CMS Made Simple version 1.2.2 and one of the latest versions of MySQL (Sorry, I do not know what version exactly is installed on the server).
I have an integer variable in the php code and when I try insert it into the database, I get 0 instead of null values.
Here is a code snippet

Code: Select all

$sql = 'INSERT INTO '.cms_db_prefix().SOME_TABLE;
$sql .= ' (x, year) VALUES (?,?) ';
$dbresult = & $gCms->db->Execute($sql, array($this->_x, $this->_year));
year is the integer variable.
My first guess was that the corresponding field in SOME_TABLE is not null, but it is nullable.
How can I insert null into an integer column in the table?
Last edited by al_anchorite on Fri Jul 25, 2008 6:44 am, edited 1 time in total.
Post Reply

Return to “Developers Discussion”