Complete the sentence.
What makes PHP such a common lanaguge of choice?
Discussion on:
View:
Show:
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=
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);
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);
- Keyboard Shortcuts:
- Prev
- Next
- Toggle









































