I have an xml column setup in a table on a SQL Server 2005 database and I am trying to add a node to the xml tree through php 5.2. The structure of the xml consist of a root node with name "YearsAttended" and child nodes with a name of "year". Below is the current sql script I am running.
DECLARE @PID int
SET @PID = 8112
IF (SELECT Years FROM YearsAttended WHERE ParticipantID=@PID) IS NULL
UPDATE YearsAttended Set Years = '<YearsAttended></YearsAttended>'
WHERE ParticipantID = @PID;
UPDATE YearsAttended
SET Years.modify('insert <year>2003</year> as first into (/YearsAttended)[1]')
WHERE ParticipantID = @PID;
The first UPDATE statement works fine however I can not get the second update statement to work in php 5.2. However, it does work through SQL Server Management Studio while targeting the same database.
The php code I am currently using looks like:
$yaQuery = "DECLARE @PID int
SET @PID = 8112
IF (SELECT Years FROM YearsAttended WHERE ParticipantID=@PID) IS NULL
UPDATE YearsAttended Set Years = '<YearsAttended></YearsAttended>'
WHERE ParticipantID = @PID;
UPDATE YearsAttended
SET Years.modify('insert <year>2015</year> as first into (/YearsAttended)[1]')
WHERE ParticipantID = @PID;";
$yaResult = mssql_query($yaQuery);
if(!$yaResult)
{
die("Error: " . mssql_get_last_message());
}
No errors are being thrown, but the node <year>2015</year>
is not inserted into
<YearsAttended></YearsAttended>
in php 5.2. I have also tried separating the query into 2 different mssql_query calls but the same issue occurs. I'm fairly new to php so I wouldn't doubt if I am overlooking something. Any ideas?
Note: 8112 and 2015 will be replaced with php variables.