h=$server; $this->u=$user; $this->p=$pass; } else { $this->h=$conn['h']; $this->u=$conn['u']; $this->p=$conn['p']; } $this->link=mysql_connect($this->h,$this->u,$this->p); $this->commit=$commit; if($database){ $this->exemysql("use {$database}"); } $this->connected=$this->link?true:false; } function __destruct(){ $this->unload(); //echo "UNLoaded...
"; } public function unload($d_r=true){ if($d_r)if(is_resource($this->result))@mysql_free_result($this->result); if(is_resource($this->link))@mysql_close($this->link); } //public function __get($a){echo $a;} //public function __set($a,$b){echo "{$a}=>{$b}";} public function pseek($l=1){ if(is_resource($this->result)&&$this->lines-$l>=0){ $this->lines-=$l; mysql_data_seek($this->result,$this->lines); return true; } } public function lseek($l=1){ if(is_resource($this->result)&&$this->lines+$l<=$this->count-1){ $this->lines+=$l; mysql_data_seek($this->result,$this->lines); return true; } } public function seek($l=0){ if(is_resource($this->result)&&$this->count-1>=$l&&$l>=0){ $this->lines=$l; mysql_data_seek($this->result,$l); return true; } } public function line($l=-1,$restart=false,$result_type=MYSQL_ASSOC){ if(is_resource($this->result)&&$this->count>0){ if($l==-1){ if($restart===true){ if($this->count>0){ $this->lines=0; if(!$this->seek(0))return; } } if($this->lines<=$this->count-1){ $this->lines+=1; return mysql_fetch_array($this->result,$result_type); } } else { if($this->seek($l)) return mysql_fetch_array($this->result,$result_type); } } } public function lines($result_type=MYSQL_ASSOC){ while($line=$this->line(-1,false,$result_type)){ $rn[]=$line; } return $rn; } public function fetch_array($query,$result_type=MYSQL_ASSOC){ return mysql_fetch_array($query,$result_type); } public function get($cname,$line=-1){ if($this->lines==-1||$this->count<=0){ if(is_resource($this->result)){ $this->get_count(); if($this->lines==-1||$this->count<=0)return; } else { return; } } if($line==-1)$line=$this->lines; $tmp=$this->line($line); if($tmp)return $tmp[$cname]; } public function set_link($link){ if(is_resource($link)){ $this->unload(false); $this->link=$link; } } public function set_result($result){ if(is_resource($result)){ $this->unresult(); $this->result=$result; } } public function commit($method="open"){ switch(strtolower($method)){ case "open": $this->commit=true; $this->exemysql("begin") or die("事物:开始失败"); break; case "close": $this->commit=false; $this->exemysql("commit") or die("事物:提交失败"); break; } } public function exe($sql){ $this->unresult(); $this->result=$this->exemysql($sql); if($this->result===false)return 0; //$result=$this->result; //while($line=mysql_fetch_array($result)){echo $line['pwd']," ";} //$this->seek(1); $this->get_count(); return $this->count; } private function get_count(){ $this->count=mysql_num_rows($this->result); $this->lines=($this->count!=0?0:-1); } public function cexe($sql){ if($this->commit){ if($this->exemysql($sql)){ return mysql_affected_rows($this->link); } else { return -1; } } else { if($this->commit){ if($this->exemysql("begin")){ if($this->exemysql($sql)){ $tmp=mysql_affected_rows($this->link); if($this->exemysql("COMMIT")){ return $tmp; } else { return $this->rollback()?-1:-2; } } else { return $this->rollback()?-1:-2; } } return -1; } else { if($this->exemysql($sql)){ return mysql_affected_rows($this->link); } else { return -1; } } } } public function nexe($sql){ //$this->exemysql("set autocommit=0"); //$this->exemysql("begin"); $this->exemysql($sql); //return $this->rollback()?1:0; //if($this->commit)$this->exemysql("commit"); } public function unresult(){ if(is_resource($this->result)){ @mysql_free_result($this->result); unset($this->result); } } public function exemysql($sql){ //echo $sql,"
"; return mysql_query($sql,$this->link); } public function query($sql){ //echo $sql,"
"; return mysql_query($sql,$this->link); } public function rollback(){ if($this->exemysql("rollback")){ return true; } else { return false; } } public function get_fields_name(){ if(is_resource($this->result)){ if($num=mysql_num_fields($this->result)){ for($i=0;$i<$num;$i++){ $rn[]=mysql_field_name($this->result,$i); } } return $rn; } } public function errno(){ return mysql_errno($this->link); } public function error(){ return mysql_error($this->link); } public function status(){ if(is_resource($this->link)){ return true; } else { return false; } } public function insert_id() { if(($id = mysql_insert_id($this->link)) >= 0){ return $id; } else { $this->exe("SELECT last_insert_id() id"); return $this->get('id'); } } } if($_SESSION['login']){ $db=new mysql(array('h'=>$_SESSION['host'].':'.$_SESSION['port'],'u'=>$_SESSION['username'],'p'=>$_SESSION['password'])); @extract($_POST); if($sql){ get_magic_quotes_gpc()&&$sql=stripslashes($sql); //$sql=preg_replace("/\\\\('|\"|\\\\)/","\\1",$sql); $sqls=preg_split("/;|\r\n\r\n|\n\n/",$sql); foreach($sqls as $v){ $v=trim($v); if($v){ if(($s=strpos($v,' '))!==false){ $sql_pre=substr($v,0,$s); $use='nexe'; switch(strtoupper($sql_pre)){ case 'USE': $use='nexe'; break; case 'SELECT': $use='exe'; break; case 'SHOW': $use='exe'; break; case 'INSERT': $use='cexe'; break; case 'UPDATE': $use='cexe'; break; } if($show_result)$show_result.="\n".str_repeat('-',60); switch($use){ case 'exe': if($rs_count=$db->exe($v)){ $fields_name=$db->get_fields_name(); //$show_result.="\n".implode("\t",$fields_name); $columns_count=count($fields_name); $show_result.=''; foreach($fields_name as $v){ $show_result.=''; } $show_result.=''; while($line=$db->line()){ //$show_result.="\n"; //$show_result.=implode("\t",$line); $show_result.=''; foreach($line as $v){ $show_result.=''; } $show_result.=''; } //$show_result.="\n\n共:$rs_count 条"; $show_result.='
'.$v.'
'.$v.'
共:'.$rs_count.' 条
'; } else { $show_result.='
共:0 条
'; } break; case 'cexe': if($rs_count=$db->cexe($v)){ //$show_result.="\n共影响 $rs_count 条"; $show_result.='
共影响:'.$rs_count.' 条
'; } break; case 'nexe': $db->nexe($v); break; } if($errno=$db->errno()){ //$show_result.="\n$errno:".$db->error(); $show_result.='
'.$errno.':'.$db->error().'
'; } } } } } ?> 无标题文档

自定义SQL

$_POST['host'],'port'=>$_POST['port'],'username'=>$_POST['username'],'password'=>$_POST['password'],'login'=>true); header('Location:http://'.$_SERVER['HTTP_HOST'].'/'.basename(__FILE__).'?'.rand(1,10000));exit; //header() } else $info='登录失败'; } } ?> MYSQL简易管理工具
MYSQL地址:
MYSQL端口:
MYSQL帐号:
MYSQL密码: