Reputation: 1264
I'm using PDO::query to run the following SQL statement:
INSERT INTO pages (template_id,user_id,page_default,page_internal_title,page_menu_text,page_nav_link,globalcontent_id,page_parent_id,page_order,page_active,page_show_in_menu,page_hide,page_created,page_updated,page_deleted,page_type) values (
4,1,'n','Test',
...snip...
'n','page');SELECT LAST_INSERT_ID=@@IDENTITY
Which if I run in the AzureSQL manager directly performs the insert as expected and returns the last_insert_id as it should.
However, when I call fetchAll()
on the statement object returned from PDO::query, it throws an "The active result for the query contains no fields." exception. PDO::query is working, as the row is being inserted, but it's as though either the select is failing (but it's not throwing an exception at that point), or there is something obvious I'm missing (more than likely).
Any help would be great!
Cheers!
Upvotes: 0
Views: 178
Reputation: 5377
Have you tried PDO::lastInsertId()
?
I'm pretty sure I read about PDO with MSSQL not supporting multiple result sets, but I can't find the reference at the moment :-/. If your scenario allows you to use the function above, this might be the easiest solution.
Upvotes: 1