📄 class_mysql.php
字号:
<?php
class mysql extends database{
public function __construct($host,$user,$password,$database=NULL){
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
$this->conn=@mysql_connect($host,$user,$password) or die('<h3>Can not connect to MySQL Server.</h3>'.mysql_error());
$database && $this->selectDb($database);
}
public function selectDb($database){
$this->database=$database;
@mysql_select_db($this->database) or die('<h2>Error while select_db</h2>'.mysql_error());
}
public function query($sql){
parent::query($sql);
if(strtolower(substr(trim($sql),0,6))=='select'){
$this->QueryType='select';
$pattern = '/select\s(.+)\sfrom/im';
$tmp_sql=preg_replace($pattern,'select count(*) from',$sql);
$this->result=mysql_query($tmp_sql);
$rs=$this->getRecord();
$this->RecordCount=$rs['count(*)'];
$this->PageCount=($this->PageSize)?ceil($this->RecordCount/$this->PageSize) : 1 ;
$this->getCurrentPage($this->PageStr);
if($this->PageSize){
$this->sql=$sql.sprintf(" limit %d,%d",($this->CurrentPage-1)*$this->PageSize,$this->PageSize);
}
}
$this->result=mysql_query($this->sql,$this->conn) or die(mysql_error().' <b>'.$sql.'</b>');
if(($this->RecordCount) && ($this->QueryType=='select')){
while($f=mysql_fetch_field($this->result)){
$this->FieldsArray[]=$f->name;
}
}
return $this->RecordCount;
}
public function getRecord(){
return $this->row= mysql_fetch_array($this->result);
}
public function getVector(){
if(!$this->result || !$this->RecordCount) {
return null;
}
mysql_data_seek($this->result,0); //璁板綍鎸囬拡绉诲姩鍒版渶寮
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -