When I execute the following in the MySQL console, it works fine:
INSERT INTO videos (embed_code) VALUES ('test code here'); SELECT LAST_INSERT_ID();
But, when I execute the above requests through PHP, the result is empty.
Under data abstraction, I use a database access class called DB . Here's how I tried these queries using PHP:
$embedCode = htmlentities($_POST['embed_code']); //Insert video in database **WORKS** DB::query("INSERT INTO videos (embed_code) VALUES ('$embedCode');"); //Retrieve id **DOES NOT WORK** $row = DB::getSingleRow("SELECT LAST_INSERT_ID();"); $videoId = $row[0];
It is not true for me to select a new id using embed_code, since embed_code can be repeated.
Thanks!
php mysql
Mike moore
source share