PHP FreeTDS unable insert into MSSQL

I'm able to run select statements to my sql server
 $link = mssql_connect('10.10.50.xxx', 'userx', 'pasx');

if (!$link)
    die('Unable to connect!');
if (!mssql_select_db('Camstat', $link))
    die('Unable to select database!');

$result = mssql_query("INSERT INTO [DB1].[dbo].[Footage_Age] ([DVRId] ,[CameraId]  ,[Last_Date] ) VALUES    (135456,525685,'2013-08-27')");

while ($row = mssql_fetch_array($result)) {
    var_dump($row);
}

mssql_free_result($result);

Open in new window


But I'm unable to run inserts into the DB.  The user has write permission to the sql db.  I've tried a lot of examples I've found on the net but with no success.
Captain CreeSystems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase ExpertCommented:
Are you getting any error? Are you checking the properDB and table?

Run below in SSMS and see if the row is inserting or not.

INSERT INTO [DB1].[dbo].[Footage_Age] ([DVRId] ,[CameraId]  ,[Last_Date] )
VALUES    (135456,525685,'2013-08-27')

Query looks ok to me so you need to check the php code, Debug the php code
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim RiddlesPrepress/OMS SpecialistCommented:
When performing an insert the $result on line 10 of your code is either going to be TRUE or FALSE.  It is not an object which you can use in your mssql_fetch_array() function call.

You should simply be checking if the value was TRUE or FALSE.

Try something like the following:
$link = mssql_connect('10.10.50.xxx', 'userx', 'pasx');

if (!$link) {
    die('Unable to connect!');
}
if (!mssql_select_db('Camstat', $link)) {
    die('Unable to select database!');
}

if (!mssql_query("INSERT INTO [DB1].[dbo].[Footage_Age] ([DVRId] ,[CameraId]  ,[Last_Date] ) VALUES    (135456,525685,'2013-08-27')")) {
    echo 'Unable to insert the data');
}

Open in new window

Note that there should be no need to free the result, as your insert would not generate more than one result.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
freetds

From novice to tech pro — start learning today.