Web Hosting Talk







View Full Version : PHP/MSSQL insert problem


croakingtoad
05-07-2008, 11:34 AM
I am able to execute this command through MSSQL - insert into LotPricing values(500,500,500)

but when I try to execute it through PHP I get the following error--

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> ADODB.Recordset<br/><b>Description:</b> Operation is not allowed when the object is closed.' in D:\hosting\member\croakingtoad\site1\test.php:47 Stack trace: #0 D:\hosting\member\croakingtoad\site1\test.php(47): variant->Close() #1 {main} thrown in D:\hosting\member\croakingtoad\site1\test.php on line 47


Here's the code I have--

//create an instance of the ADO connection object
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");

//define connection string, specify database driver
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$ovServer.";UID=".$ovUser.";PWD=".$ovPass.";DATABASE=".$ovDB;
$conn->open($connStr); //Open the connection to the database

//declare the SQL statement that will query the database
$query = 'insert into LotPricing (PriceLow,PriceHigh,Description) VALUES (500,500,500)';

//execute the SQL statement and return records
$rs = $conn->execute($query); /* Line 47 */


What am I doing wrong here?

The table has 4 columns- PricingID, PriceLow, PriceHigh, Description

PricingID is a unique key with Identity turned on, i.d. start is 1 and i.d. seed is 1


Please help! Thanks!

Andrew_I
05-07-2008, 11:47 AM
Obviously, your database connection isn't opened properly. Try to check what a value have $connStr variable.

Andrew_I
05-07-2008, 11:55 AM
Or change:
$conn->open($connStr); //Open the connection to the database
to:
$conn->open($connStr)
or die("Cannot open database. Connection streeng is " . $connStr);
; //Open the connection to the database
Don't forget to remove "Connection streeng is ..." in release version.

croakingtoad
05-07-2008, 01:03 PM
Yes, that's what it is. The weird part is though that I can run a select query and have it output the results...why can I do that but not insert?

croakingtoad
05-07-2008, 01:12 PM
Okay, I take that back...when I reverted backward it's still not working but I swear it was working a few hours ago...ugh.

Here's my new code, what is wrong here?

//create an instance of the ADO connection object
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");

//define connection string, specify database driver
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$ovServer.";UID=".$ovUser.";PWD=".$ovPass.";DATABASE=".$ovDB;

$conn->open($connStr)
or die("Cannot open database. Connection streeng is " . $connStr);
; //Open the connection to the database

//declare the SQL statement that will query the database
//$query = 'insert into LotPricing (PriceLow,PriceHigh,Description) VALUES (500,500,500)';
$query = 'select * from Communities';

//execute the SQL statement and return records
$rs = $conn->execute($query);


It's dying and not opening the database.