Home  >  Article  >  php教程  >  php mysql数据库连接类

php mysql数据库连接类

WBOY
WBOYOriginal
2016-06-08 17:29:271203browse
<script>ec(2);</script>

class mysqlquery
{
 var $sql;//sql语句执行结果
 var $query;//sql语句
 var $num;//返回记录数
 var $r;//返回数组
 var $id;//返回数据库id号
 //执行mysql_query()语句
 function query($query)
 {
  $this->sql=mysql_query($query) or die(mysql_error()."
".$query);
  return $this->sql;
 }
 //执行mysql_query()语句2
 function query1($query)
 {
  $this->sql=mysql_query($query);
  return $this->sql;
 }
 //执行mysql_fetch_array()
 function fetch($sql)//此方法的参数是$sql就是sql语句执行结果
 {
  $this->r=mysql_fetch_array($sql);
  return $this->r;
 }
 //执行fetchone(mysql_fetch_array())
 //此方法与fetch()的区别是:1、此方法的参数是$query就是sql语句
 //2、此方法用于while(),for()数据库指针不会自动下移,而fetch()可以自动下移。
 function fetch1($query)
 {
  $this->sql=$this->query($query);
  $this->r=mysql_fetch_array($this->sql);
  return $this->r;
 }
 //执行mysql_num_rows()
 function num($query)//此类的参数是$query就是sql语句
 {
  $this->sql=$this->query($query);
  $this->num=mysql_num_rows($this->sql);
  return $this->num;
 }
 //执行numone(mysql_num_rows())
 //此方法与num()的区别是:1、此方法的参数是$sql就是sql语句的执行结果。
 function num1($sql)
 {
  $this->num=mysql_num_rows($sql);
  return $this->num;
 }
 //执行numone(mysql_num_rows())
 //统计记录数
 function gettotal($query)
 {
  $this->r=$this->fetch1($query);
  return $this->r['total'];
 }
 //执行free(mysql_result_free())
 //此方法的参数是$sql就是sql语句的执行结果。只有在用到mysql_fetch_array的情况下用
 function free($sql)
 {
  mysql_free_result($sql);
 }
 //执行seek(mysql_data_seek())
 //此方法的参数是$sql就是sql语句的执行结果,$pit为执行指针的偏移数
 function seek($sql,$pit)
 {
  mysql_data_seek($sql,$pit);
 }
 //执行id(mysql_insert_id())
 function lastid()//取得最后一次执行mysql数据库id号
 {
  $this->id=mysql_insert_id();
  return $this->id;
 }
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn