I have the following SQL that works directly in MySQL
INSERT INTO `my_tabel` (`data`) VALUES ("my_value");
SELECT * from `my_tabel` ORDER BY `id` DESC LIMIT 1
It inserts a row, and then gets the new row so that I can return the new ID to use later.
When I try to run the SQL in codeIgniter I get an error message stating that I have an error in my SQL
$m = new my_model();
$sql = 'INSERT INTO `my_tabel` (`data`) VALUES ("'.$my_value.'"); SELECT * from `my_tabel` ORDER BY `id` DESC LIMIT 1';
$m->query($sql);
Running a single SQL statement works fine in codeIgniter, but not when I add the second SELECT... statement.
Any ideas (or alternative solutions)?
Thanks
$m->query('INSERT INTO `my_tabel` (`data`) VALUES (?); SELECT * from `my_tabel` ORDER BY `id` DESC LIMIT 1', array($my_value));. More info at the bottom of this page: codeigniter.com/user_guide/database/queries.htmlmysql_real_escape_string($value), I didn't add it to the question to keep the code simpler. I can see your solution adds security, so I will add that toomysql_real_escape_stringanymore.