Files
interactive/gms/SKBB/httpd/wwwroot/sh_monitor/inc/mysql.inc.bk
T
2026-08-07 17:38:18 +09:00

123 lines
3.0 KiB
Plaintext

<?php
define('SQL_ASSOC', MYSQL_ASSOC);
define('SQL_NUM', MYSQL_NUM);
define('SQL_BOTH', MYSQL_BOTH);
define('CRLF', "\r\n");
class dbconnect
{
var $showError;
var $dbc;
function dbconnect($host, $user, $pass, $base, $file = '', $line = 0)
{
//echo $host." ".$user." ".$pass;
//[ string $server = ini_get("mysql.default_host")
//[, string $username = ini_get("mysql.default_user")
//[, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int $client_flags = 0 ]]
//]
//]
//]
//if(!$this->dbc = mysql_connect($host, $user, $pass))
if(!$this->dbc = mysql_connect($host, $user))
{
$error = 'Cannot connect to MySQL server. In file '.$file.' in line '.$line.'. Date: '.date('Y-m-d H:i:s').'<br />'.CRLF;
die($error);
}
if(!@mysql_query("USE ".$base, $this->dbc))
{
$error = 'Error <b>'.mysql_error($this->dbc).'</b> in query <b>'.$query.'</b>. In file '.$file.' in line '.$line.'. Date: '.date('Y-m-d H:i:s').'<br />'.CRLF;
die($error);
}
$this->showError = true;
}
function query($query, $file = '', $line = 0)
{
if(!$result = @mysql_query($query, $this->dbc))
{
$error = 'Error <b>'.mysql_error($this->dbc).'</b> in query <b>'.$query.'</b>. In file '.$file.' in line '.$line.'. Date: '.date('Y-m-d H:i:s').'<br />'.CRLF;
if($this->showError)
{
echo $error;
}
}
return new dbcResult($result);
}
function query_bool($query, $file = '', $line = 0)
{
if(!$result = @mysql_query($query, $this->dbc))
{
$error = 'Error <b>'.mysql_error($this->dbc).'</b> in query <b>'.$query.'</b>. In file '.$file.' in line '.$line.'. Date: '.date('Y-m-d H:i:s').'<br />'.CRLF;
if($this->showError)
{
echo $error;
}
}
return ($result?true:false);
}
function insert_id()
{
$id = $this->firstCell("SELECT LAST_INSERT_ID() as id");
return $id;
}
function fetch_array($query, $type = SQL_BOTH)
{
$result = $this->query($query);
return $result->fetch_array($type);
}
function first_cell($query)
{
$result = $this->query($query);
$row = $result->fetch_array(SQL_NUM);
return $row[0];
}
function change_base($base, $file = '', $line = 0)
{
if(!$result = @mysql_query('USE '.$base, $this->dbc))
{
$error = 'Error <b>'.mysql_error($this->dbc).'</b> in query <b>'.$query.'</b>. In file '.$file.' in line '.$line.'. Date: '.date('Y-m-d H:i:s').'<br />'.CRLF;
if($this->showError)
{
echo $error;
}
}
return ($result?true:false);
}
function close()
{
@mysql_close($this->dbc);
unset($this);
}
}
class dbcResult
{
function dbcResult($result)
{
$this->result = $result;
}
function fetch_array($type = SQL_BOTH)
{
return @mysql_fetch_array($this->result, $type);
}
function first_cell()
{
$row = @mysql_fetch_row($this->result);
return $row[0];
}
function num_rows()
{
return @mysql_num_rows($this->result);
}
}
?>