I have the following SQL query:
INSERT INTO tags(name) VALUES(LOWER(#[tag]));
SELECT LAST_INSERT_ID() AS ID;
I'm using it on MySQL using PHP PDO and i get the following error:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: General error' in
/home/cabox/workspace/backend/Toolbox.php:62 Stack trace: #0
This is my PHP Code:
$NI = (int)($DB->query(get_query("CREATE_TAG",[
"tag" => strtolower($name)
]))->fetch(PDO::FETCH_ASSOC)["ID"]);
The get_query
functions returns a query after all #[]
are replaced acording to the array in the second parameter. (
get_query("CREATE_TAG",["tag" => strtolower("MyTagName")])
will return
INSERT INTO tags(name) VALUES(LOWER("MyTagName"));
SELECT LAST_INSERT_ID() AS ID;
)
Can't i insert then select in the same query?
EDIT: I used this:
INSERT INTO tags(name) OUTPUT INSERTED.ID VALUES(LOWER(#[tag]));
and it worked just fine.