Hello all, I’m new to Yii and while developing my first project on a Windows 8 PC, using Yii ver. 1.1.14 on a XAMPP ver 1.8.3 installation (php 5.5.3 - Mysql 5.6) I get the above error.
Specifically I’m attempting to run a DAO sql statement from my yii code that does an insert in a table (as_members) and then subsequently in the same statement selects the auto incremented ID value of the record inserted:
$q = "INSERT INTO `as_members`(`MB_TYPE`, `MB_EMAIL`, `MB_COUNTRY`, `MB_STATE`, `MB_BIRTHDAY`) "
. "VALUES($gender, '$email', $country, $area_city, '$sdt'); SELECT LAST_INSERT_ID(); ";
$cmd = Yii::app()->db->createCommand($q);
$mb_id = $cmd->queryScalar();
I get the following run-time error:
CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error. The SQL statement executed was: INSERT INTO as_members
(MB_TYPE
, MB_EMAIL
, MB_COUNTRY
, MB_STATE
, MB_BIRTHDAY
) VALUES(1, ‘aaaaa@yahoo.com’, 2, 58, ‘1968-08-11’); SELECT LAST_INSERT_ID();
The statement executes OK from a Windows SQL client (HeidiSQL) I am using. Furthermore when I break the sql statement in a insert statement and a select statement and execute them as 2 steps from Yii the code works!
What am I missing here? Why does my initial code produces an error?
Thanks in advance