Hi all,
(1) The "standard method" for handling errors when executing queries to
a mysql database, which is shown in most tutorials and books is:
mysql($query) or die("select/insert/update/delete query failed for
table_name");
Actually that is hardly what should be done in a good application.
Every other function has a means of returning a value, often true/false
or "0"/"1".
I feel it is best if we had something like :
$success = mysql($query);
if ( $sucess) {
//do something
} else {
//log error
//show customized error page
}
True, we can do the following:
mysql($query) or my_own_db_error_handler();
Is there anything that I dont know or any better idea?
Also, a basic question I have is - why we do have to do "or die()"? Is
it because we need to ensure that a moment a db script gives an error,
we have a query that has failed, so as damage control, we immediately
terminate the script, knowing that some queries have been executed and
others have not.
If this is the reason to use "or die()" is it not better to use
mysql_query("start transaction") and mysql_query("commit") or
"rollback" and put the commit at the end of the script and the rollback
in the above mentioned my_own_db_error_handler() ?
Is this a good way?
(2) Also, most big web hosts (shared hosting - I cannot afford to set
up a host myself or even dedicated hosting) do not have PHP5, which
has MySQLi which has much better MySQL functionality(bind variables
etc) . They have PHP 4.3.x. I am under the impression that for an
efficient PHP4 app you need to use the procedural style, since PHP4's
OO features are "slow and inefficient". Am i correct ?
Thanks in advance for your responses,
Regards,
JS 1 2404
Joseph S. wrote: Hi all, (1) The "standard method" for handling errors when executing queries to a mysql database, which is shown in most tutorials and books is:
mysql($query) or die("select/insert/update/delete query failed for table_name");
Actually that is hardly what should be done in a good application. Every other function has a means of returning a value, often true/false or "0"/"1". I feel it is best if we had something like :
$success = mysql($query);
if ( $sucess) { //do something } else { //log error //show customized error page }
True, we can do the following:
mysql($query) or my_own_db_error_handler();
Is there anything that I dont know or any better idea?
Also, a basic question I have is - why we do have to do "or die()"? Is it because we need to ensure that a moment a db script gives an error, we have a query that has failed, so as damage control, we immediately terminate the script, knowing that some queries have been executed and others have not. If this is the reason to use "or die()" is it not better to use mysql_query("start transaction") and mysql_query("commit") or "rollback" and put the commit at the end of the script and the rollback in the above mentioned my_own_db_error_handler() ? Is this a good way?
(2) Also, most big web hosts (shared hosting - I cannot afford to set up a host myself or even dedicated hosting) do not have PHP5, which has MySQLi which has much better MySQL functionality(bind variables etc) . They have PHP 4.3.x. I am under the impression that for an efficient PHP4 app you need to use the procedural style, since PHP4's OO features are "slow and inefficient". Am i correct ?
Thanks in advance for your responses, Regards, JS
I agree. Using ... or die() is just a lazy way of damage control. I
don't use it.
A failed request should never terminate the program. Rather, it should
return some kind of failure result and allow the caller to determine
what action should be taken. And good programming practices allows the
caller to handle this "failed" result gracefully.
Unfortunately, this and other poor programming practices seem to be more
pervasive in PHP books than most other languages.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
================== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Trev |
last post by:
SQL Server 2000 BE, Access 2002 FE.
I want to write a stored procedure, that will among other things log
errors to a table, I want to be able to report a summary of work done
and errors to the...
|
by: smorrey |
last post by:
Hello all, this might better be suited for the MySQL newsgroup, but I
figured I'ld post here and see if anyone can help me.
I'm trying to create a simple transaction handling system where users...
|
by: Mairhtin O'Feannag |
last post by:
Hello,
I have a client (customer) who asked the question : "Why would I buy and
use UDB, when MySql is free?"
I had to say I was stunned. I have no experience with MySql, so I was
left sort...
|
by: jlee |
last post by:
I'm pretty much a newbie on mysql, and I need some help.
I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4
(i386) on a server hosting an active website.
The site's developer...
|
by: Ike |
last post by:
Recently, I began using a different MySQL verver (i.e. different machine as
well as different version#, going from 4.12a to 4.1.9 max).
The following query used to work:
select firstname,...
|
by: PowerLifter1450 |
last post by:
I've been having a very rough time installinig mySQL on Linux. I have
been following the instructions form here:
http://www.hostlibrary.com/installing_apache_mysql_php_on_linux
Everytime I get to...
|
by: Kevin Frey |
last post by:
One of my chief criticisms of validators in an ASP.NET page is that they can
result in a developer re-implementing much of the "business logic" of a
transaction at the page level.
Assuming we...
|
by: cwho.work |
last post by:
Hi!
We are using apache ibatis with our MySQL 5.0 database (using innodb
tables), in our web application running on Tomcat 5. Recently we
started getting a number of errors relating to...
|
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= |
last post by:
Hi there guys,
My doubt is related with MySQL and Transactions (InnoDB) so here it
goes:
I have a query like this:
$query = 'START TRANSACTION; ';
$query .= 'UPDATE sections ';
$query .=...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |