note 33120 deleted from ref.mysql by didou
| From: | didou@php.net | Date: | Tue, 17 Jun 2003 09:52:57 +0000 |
| Subject: | note 33120 deleted from ref.mysql by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50476@lists.php.net to get a copy of this message | ||
Note Submitter: andrejs@naumovs.de
----
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
$res = mysql_connect($host,$user,$password,1);
echo ".....". mysql_select_db
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();
}
}//~
?>