MYSQL PDO return type strange conversion

buzzstpt

New Member
I have the following table definition in MYSQL\[code\]CREATE TABLE IF NOT EXISTS `test_cases` ( `id` int(10) unsigned NOT NULL auto_increment, `exercise_id` int(10) unsigned NOT NULL, `author_id` int(10) unsigned NOT NULL, `input_1_value` varchar(255) default NULL, `input_2_value` varchar(255) default NULL, `input_3_value` varchar(255) default NULL, `input_4_value` varchar(255) default NULL, `input_5_value` varchar(255) default NULL, `output_value` varchar(255) default NULL, PRIMARY KEY (`id`), KEY `test_cases_ibfk_1` (`exercise_id`), KEY `author_id` (`author_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3218 ;\[/code\]I have the following entry into this table\[code\]INSERT INTO `test_cases` (`id`, `exercise_id`, `author_id`, `input_1_value`, `input_2_value`, `input_3_value`, `input_4_value`, `input_5_value`, `output_value`) VALUES(560, 145, 496, '0', NULL, NULL, NULL, NULL, '0')\[/code\]I have the following query to get the above row from the table\[code\]SELECT id, exercise_id, author_id, input_1_value, input_2_value, input_3_value, input_4_value, input_5_value, output_value FROM test_cases WHERE exercise_id=145\[/code\]I'm interested in, and having problems with, the value in \[code\]input_1_value\[/code\]. Running the query in phpMyAdmin will return the value as '0', which is as expected. However running the following php script returns the value as 'true' which is completely left field and leaving me and my project supervisor stumped. The php script is below...\[code\]$db = DBCxn::getCxn(); $sql = "SELECT id, exercise_id, author_id, input_1_value, input_2_value, input_3_value, input_4_value, input_5_value, output_value FROM test_cases WHERE exercise_id=:exid";$st=$db->prepare($sql);$st->bindParam(":exid", $exerciseId, PDO::PARAM_INT); // $exerciseID == 145$st->execute();$row = $st->fetch(); // default fetch mode is PDO::FETCH_BOTHecho $row['input_1_value'];\[/code\]this echos 'true'!!!! why??? why does it not print '0'???for even more information using \[code\]print_r($row);\[/code\] I get the following output\[code\]Array ( [id] => 560 [0] => 560 [exercise_id] => 145 [1] => 145 [author_id] => 496 [2] => 496 [input_1_value] => true [3] => true [input_2_value] => [4] => [input_3_value] => [5] => [input_4_value] => [6] => [input_5_value] => [7] => [output_value] => true [8] => true ) \[/code\]Note \[code\]output_value\[/code\] is also returned as 'true' when it should be '0'. Does anyone know what is going on here? Any help is appreciated. GREATLY appreciated.
 
Back
Top