MS SQL insert with PHP

lvmllc used Ask the Experts™
I can query and print to screen data from my MS SQL db, but have problems inserting new data. Any help appreciated.
$userID = 49;
$something = "fun";

//insert to table does not work
$sql="INSERT INTO sde.MYTBLE (userID, something) VALUES ($userID, $something)"; 
mssql_query($sql) or print "Error inserting data to database.<br>";

//query works here
$result = mssql_query('select userID, something FROM sde.MYTBLE');
while ($row = mssql_fetch_array($result)) {
    printf("ID: %s  Name: %s", $row[0], $row[1]."<br>");  

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Is $something a string? If so, it will need single quotes around it.

eg: $sql="INSERT INTO sde.MYTBLE (userID, something) VALUES ($userID, '$something')";


I fixed the '' but still have issues so I created a new db called dbo.cjsTable and I was able to insert. So my issue is inserting into sde.MYTBLE.   I can query the sde.MyTBLE just fine.

The sde is a schema for ArcGIS and I am able to connect to the table and edit it via ArcGIS - thus I suspect it is a permissions issue that keeps me from inserting via the PHP script.

How do I go about telling a table that is part of the SDE that I want the sa to also be able to INSERT etc?

Well, that's a different question entirely. You'd need to alter the connectionstring to use the sa user.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial