Jump to content

Recommended Posts

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);
}

  • 1 month later...

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?

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?

$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!

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

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.