note 33121 added to ref.mysql

From: Date: Tue, 17 Jun 2003 09:40:34 +0000
Subject: note 33121 added to ref.mysql
Groups: php.notes 
Request: Send a blank email to php-notes+get-50474@lists.php.net to get a copy of this message
Simply class for MySQL with debug function. Try it's! ______________________ class mysql_db{ var $errmsg; function mysql_db(){ // constructor is empty } function getConnect($host,$only_db,$user,$password){ // connect return mysql_select_db($only_db, mysql_connect($host,$user,$password)); } function runSQL($sql,$debug = FALSE){ //print SQL and ERROR in HTML format: if($debug) echo"---- SQL:$sql"; $result_identifier = mysql_query($sql); $mysql_error = mysql_error(); if($debug && $mysql_error != ""){ // build errmsg for html and log.txt echo"---- ERROR:$mysql_error"; $this->errmsg = "---- SQL:\r\n\t$sql\r\n--- ERROR:\r\n\t$mysql_error"; } if($result_identifier == "")return; // if (eregi("^select",$sql)) // { //SELECT if (eregi("count\(",$sql) || eregi("max\(",$sql) || eregi("min\(",$sql)){ // get count,max,min return mysql_result($result_identifier,0); } elseif (eregi("limit 0\,1$",$sql)) { if (eregi("^.+,.+FROM.+",$sql)) { // get object return mysql_fetch_object($result_identifier); } else { //number of rows? if(mysql_num_rows($result_identifier) == 0)return; // get only once value return mysql_result($result_identifier,0); } } else { // get result values to array $i=0; while ($result = mysql_fetch_object($result_identifier)){ $result_array[$i] = $result; $i++; } return $result_array; } } else { // return $result_identifier; } } function runAPI($api) { // return $api; } function connectClose() { // connect close return mysql_close(); } }//~ ?> ---- Manual Page -- http://www.php.net/manual/en/ref.mysql.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33121 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33121&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33121&report=yes

« previous php.notes (#50474) next »