Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all articles
Browse latest Browse all 391

PHP SQLSRV - ignores scalar variable declaration in multi-line batch

$
0
0

My TSQL string looks like this:

INSERT INTO contacts (firstName, lastName) VALUES ('jon', 'snow') 
DECLARE @IDcontacts VARCHAR(200)
SET @IDcontacts = @@IDENTITY;

INSERT INTO emailAddresses (ownerId, emailAddress) VALUES (@IDcontacts, 'jon@thewall.com') 

INSERT INTO emailAddresses (ownerId, emailAddress) VALUES (@IDcontacts, 'jon@winterfell.com') 

INSERT INTO emailAddresses (ownerId, emailAddress) VALUES (@IDcontacts, 'thebastard@winterfell.com') 

I run this using sqlsrv_query() and it returns four errors: "Must declare scalar variable @IDcontacts".  It looks declared to me.

It appears as if the query command is executing every line in a separate scope (returning an error for each one), but that's just a guess.  There must be a way to make this work properly.  After all, I suspect that with complex objects (children and grand children and even great-grandchildren) popping out after every insert to check the identity and pass it to all the children would be pretty innefficient.

Help?



Viewing all articles
Browse latest Browse all 391

Trending Articles