Re: Query/Error

From: Date: Sat, 18 May 2002 06:22:27 +0000
Subject: Re: Query/Error
Groups: php.general 
Request: Send a blank email to php-general+get-98161@lists.php.net to get a copy of this message
Anthony, I find it is useful to write code such that every outcome, however remote, is handled by your code: $query = "INSERT INTO ... blah "; // pconnect, select and query if ($link_identifier = mysql_pconnect(DBSERVERHOST, DBUSERNAME, DBPASSWORD)) { if ( mysql_select_db(DBNAME, $link_identifier)) { // run the query $queryResultHandle = mysql_query($query, $link_identifier) or die( mysql_error() ); $rows = mysql_affected_rows($link_identifier); // decide what to do with the results switch( $rows ) { case 0: echo"Count for rows inserted is zero. No data was changed.<br>\n"; break; case 1: // do something break; default: echo"Process anomaly. Notify the webmaster.<br>\n"; } // switch( $rows ) { }else{ // select echo mysql_error(); } }else{ //pconnect echo mysql_error(); } The $rows handling will vary depending on the nature of your query: mysql_num_rows() mysql_affected_rows() Kind Regards, Richard Creech richardc@dreamriver.com 250.744.3350 Pacific Time Canada Dreamriver Software Powers the Net http://www.dreamriver.com } Anthony wrote: Message-Id: <4.3.2.7.2.20020517052333.00b13460@mailbox.bellatlantic.net> Date: Fri, 17 May 2002 05:35:51 -0400 To: php-general@lists.php.net From: Anthony Rodriguez <sbwi@bellatlantic.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Query/Error <snip> What code can I add to the script to find out the error of the query?

« previous php.general (#98161) next »