📄 class.query.php
字号:
<?php if (!defined("_class_query_inc")) : ?>
<?php define("_class_query_inc",1); ?>
<?php
$db = @mysql_connect('localhost', 'root', '');
if (!$db)
die("<h1 align=center>Unable connect to server!!!</h1>");
if (!(mysql_select_db('project_management', $db)))
die("<h1 align=center>Unable connect to database!!!</h1>");
define("DEBUG_MODE", true);
class query{
var $query;
function query($query=''){
$this->query = $query;
}
function select($query=''){
global $db;
if ($query) $this->query = $query;
$result = mysql_query($this->query, $db);
if (!$result){
$this->error(mysql_error($db));
return array();
}
$rows = array();
while ($row = mysql_fetch_array($result)) $rows[sizeof($rows)+1] = $row;
return $rows;
}
function select1($query=''){
$result = $this->select($query);
if (sizeof($result)==0) return 0;
return $result[1];
}
function insert($query=''){
global $db;
if ($query) $this->query = $query;
$result = mysql_query($this->query, $db);
if (!$result){
$this->error(mysql_error($db));
return 0;
}
return mysql_insert_id($db);
}
function exec($query=''){
global $db;
if ($query) $this->query = $query;
$result = mysql_query($this->query, $db);
if (!$result){
$this->error(mysql_error($db));
return 0;
}
return $result;
}
function update($query=''){
return $this->exec($query);
}
function delete($table, $id){
$query = "delete from $table where id=$id";
return $this->exec($query);
}
function error($message){
if(DEBUG_MODE){
echo '<span style="font-weight: bold; color: red; font-family: Verdana;">MySQL: '.$this->query.'</span><br>';
echo '<span style="font-weight: bold; color: red; font-family: Verdana;">MySQL: '.$message.'</span><br>';
}
}
}
?>
<? endif; ?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -