orange08 Posted February 27, 2009 Share Posted February 27, 2009 hi, can anyone here kindly provide me with an example of implementing commit() in php 4? i try 2 search online, but only with php 5 found... or can provide me a link with this topic? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/ Share on other sites More sharing options...
Mchl Posted February 27, 2009 Share Posted February 27, 2009 commit? There's no such function. Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-772421 Share on other sites More sharing options...
Mark Baker Posted February 27, 2009 Share Posted February 27, 2009 can anyone here kindly provide me with an example of implementing commit() in php 4?If you mean a database commit, then you also need to be using a transactional database. But assuming you are, then you'd simply execute it as a standard database query. $SQLquery = 'START TRANSACTION'; $result = mysql_query($SQLquery); $SQLquery = 'UPDATE table SET column=1 WHERE type=2'; $result = mysql_query($SQLquery); if (!$result) { $SQLquery = 'ROLLBACK'; $result = mysql_query($SQLquery); } else { $SQLquery = 'COMMIT'; $result = mysql_query($SQLquery); } Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-772434 Share on other sites More sharing options...
orange08 Posted April 11, 2009 Author Share Posted April 11, 2009 can anyone here kindly provide me with an example of implementing commit() in php 4?If you mean a database commit, then you also need to be using a transactional database. But assuming you are, then you'd simply execute it as a standard database query. $SQLquery = 'START TRANSACTION'; $result = mysql_query($SQLquery); $SQLquery = 'UPDATE table SET column=1 WHERE type=2'; $result = mysql_query($SQLquery); if (!$result) { $SQLquery = 'ROLLBACK'; $result = mysql_query($SQLquery); } else { $SQLquery = 'COMMIT'; $result = mysql_query($SQLquery); } thanks for the code, as we start the code from 'start transaction', need to close transaction or not after the query is executed? Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807117 Share on other sites More sharing options...
Mchl Posted April 11, 2009 Share Posted April 11, 2009 Both COMMIT and ROLLBACK queries end current transaction. Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807120 Share on other sites More sharing options...
orange08 Posted April 11, 2009 Author Share Posted April 11, 2009 Both COMMIT and ROLLBACK queries end current transaction. so, meant that either COMMIT or ROLLBACK must be called to complete the code? $SQLquery = 'START TRANSACTION'; $result = mysql_query($SQLquery); $SQLquery = 'UPDATE table SET column=1 WHERE type=2'; $result = mysql_query($SQLquery); if (!$result) { $SQLquery = 'ROLLBACK'; [color=red] $result = mysql_query($SQLquery);[/color] } else { $SQLquery = 'COMMIT'; $result = mysql_query($SQLquery); } i can't understand why the line of code that in red color is needed... in this case, if $result success or fail, then no more COMMIT or ROLLBACK is called...,right? Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807144 Share on other sites More sharing options...
Mchl Posted April 11, 2009 Share Posted April 11, 2009 If first query 'UPDATE table SET column=1 WHERE type=2' succeeds, then COMMIT query is send. If it fails then ROLLBACK query is send. Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807147 Share on other sites More sharing options...
orange08 Posted April 11, 2009 Author Share Posted April 11, 2009 If first query 'UPDATE table SET column=1 WHERE type=2' succeeds, then COMMIT query is send. If it fails then ROLLBACK query is send. oh, i understand now...just now, i didn't see properly and misunderstand with the code. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807155 Share on other sites More sharing options...
orange08 Posted April 12, 2009 Author Share Posted April 12, 2009 $SQLquery = 'START TRANSACTION'; $result = mysql_query($SQLquery); $SQLquery = 'UPDATE table SET column=1 WHERE type=2'; $result = mysql_query($SQLquery); if (!$result) { $SQLquery = 'ROLLBACK'; $result = mysql_query($SQLquery); } else { $SQLquery = 'COMMIT'; $result = mysql_query($SQLquery); } in what case, !$result will be met? if my SQL query WHERE clause can't be reached, will it causing !$result? can give example when !$result will happen? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807827 Share on other sites More sharing options...
Mark Baker Posted April 12, 2009 Share Posted April 12, 2009 in what case, !$result will be met? if my SQL query WHERE clause can't be reached, will it causing !$result? can give example when !$result will happen? thanks! $result can be a boolean false (fail) if there is an error in the SQL statement, or if the database cannot be accessed. If no records match the where clause, and so nothing is updated, this is not an error. You can test for this separately using the mysql_affected_rows() function Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807849 Share on other sites More sharing options...
orange08 Posted April 12, 2009 Author Share Posted April 12, 2009 in what case, !$result will be met? if my SQL query WHERE clause can't be reached, will it causing !$result? can give example when !$result will happen? thanks! $result can be a boolean false (fail) if there is an error in the SQL statement, or if the database cannot be accessed. If no records match the where clause, and so nothing is updated, this is not an error. You can test for this separately using the mysql_affected_rows() function ok, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/147126-implement-commit-in-php-4/#findComment-807907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.