MySQL- Why is LAST_INSERT_ID() not working for me?

chencydaype

New Member
I have the following code:\[code\] public function createNewGuide($userID,$guideName) { $sql =" INSERT INTO myTable(name, updated) VALUES ('$guideName', 'NOW()')"; //Process query $this->query($sql); // This inserts the new row $this->query('LAST_INSERT_ID()'); // This throws an error return $this->query_result; }\[/code\]My query function looks like this:\[code\] private function query($sql) { $this->query_result = mysql_query($sql, $this->conn) or die("Unable to query local database <b>". mysql_error()."</b><br>$sql"); } \[/code\]I get the following error:\[quote\] MySQL Database Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LAST_INSERT_ID()'\[/quote\]I've googled and looked at similar problems, but not found an answer :(I have not tried the PHP function mysql_insert_id(), as I really would like to do this using SQL.
 
Back
Top