• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 71
  • Last Modified:

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.
0
Captain Cree
Asked:
Captain Cree
1 Solution
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now