PHP MSSQL sometimes autocommits

I have php installed on a 2003 box running IIS and MSSQL. Connection is through a ODBC driver and I'm using PHP mssql functions.

If i do a insert into one table or inserts into different tables everything is fine example and i don't have to call a commit statement.

$query = "INSERT INTO table1";
$result = mssql_query($query, $link)or exit(mssql_get_last_message());

$query = "INSERT INTO table2";
$result = mssql_query($query, $link)or exit(mssql_get_last_message());


but if it try to insert another row into the same table i have to call a commit statement or the second insert errors and doesn't get inserted:

Doesn't work:

$query = "INSERT INTO table1";
$result = mssql_query($query, $link)or exit(mssql_get_last_message());

$query = "INSERT INTO table1";
$result = mssql_query($query, $link)or exit(mssql_get_last_message());

Works:

$query = "INSERT INTO table1";
$result = mssql_query($query, $link)or exit(mssql_get_last_message());

mssql_query("COMMIT");

$query = "INSERT INTO table1";
$result = mssql_query($query, $link)or exit(mssql_get_last_message());

I've tried finding this on the web and haven't had much success. I'm not doing any transactional sets so auto commit is fine for me. Just wanted to know why this is happening.
LVL 2
chemdryAsked:
Who is Participating?
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.

Chad SmithSoftware EngineerCommented:

SQL_AUTOCOMMIT_ON
SQLSetConnectOption(hdbc,
                    SQL_AUTOCOMMIT,
                    SQL_AUTOCOMMIT_ON);
0
chemdryAuthor Commented:
a little more info would be useful. Im not sure if i run that on the sql server, what hdbc is and what the scope is, does it affect all connections to all database tables? etc.

I read that odbc are by default auto commit. I checked the server properties and implicit transactions is NOT checked.

So i want to understand why this is happening.
 
0
chemdryAuthor Commented:
K I figured it out. It wasn't an auto commit issue after all. I was getting "the statement has terminated' and thought that was an auto commit issue.

Turned out my primary key for the table was id,user,datetime (mssql's timestamp is screwy to use unlike mysql's).

Well it was submitting two rows so quickly the date time wasn't different.
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
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
PHP

From novice to tech pro — start learning today.