Discussion on:

6
Comments

Join the conversation!

Follow via:
RSS
Email Alert
0 Votes
+ -
Editor
Complete the sentence.


What makes PHP such a common lanaguge of choice?
0 Votes
+ -
I like PHP because
cal@... 22nd Jun 2006
It's simple enough so that I can quickly prototype apps in it and complex enough so that I can take the prototypes and turn them into real apps.

IMHO, etc.

=C=
Does that database with php work with my t1 broadband dedicated internet?
There are a few things I would do different. My examples are for mysql but should be applicable for mysqli:


1. Check if the db connection is alive, don't assume it is.



Setup a boolean variable so you can test for S/F in an "if" statement.



sqlSuccess = true;

if(!$conn) {

include 'includes/db_connection.php';

}



2. You can put short SQL in the mysql_query(). Also, place it in an if statement to test for success/failure. You should verify S/F of each SQL execution.



if (!mysql_query("SET AUTOCOMMIT=0")) {

$sqlSuccess = false;

}

if ($sqlSuccess && !mysql_query("START TRANSACTION")) {

echo 'START TRANSACTION failed: ' . mysql_error() . mysql_errno();

$sqlSuccess = false;

}


3. In the example:

A. Not all sql statements are checked for success or failure.

B. There is an sql rollback after each SQL statement. If the second sql statement fails, why would you want to keep the first sql statement (its been committed). The rollback or commit for all insert/update/delete sql should be done last. That way every statement works or it is all rolled back.



4. After performing db inserts and updates, commit or rollback the changes as a roup.



if ($sqlSuccess) {

if (!mysql_query("COMMIT;")) {

echo "COMMIT failed: " . mysql_error() .mysql_errno() ."
";

}

} else {

$SQL = "ROLLBACK;";

if (!mysql_query("ROLLBACK;")) {

echo "ROLLBACK failed: " .
mysql_error() .mysql_errno() ."
" ;
}

}




5. Finally free resources & close db connect.

mysql_free_result($result);

$rt =mysql_close($conn);
0 Votes
+ -
No checking for 0 Balance.
Thanks for real example
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.