PHP MySQL database connection class

Source: Internet
Author: User

<?php
Class Mysqlquery
{
var $sql;//sql Statement Execution results
var $query;//sql statement
var $num//return number of records
var $r;//return array
var $id//Return database ID number
Execute mysql_query () statement
function query ($query)
{
$this->sql=mysql_query ($query) or Die (Mysql_error (). " <br> ". $query);
return $this->sql;
}
Execute mysql_query () Statement 2
function Query1 ($query)
{
$this->sql=mysql_query ($query);
return $this->sql;
}
Execute mysql_fetch_array ()
function Fetch ($SQL)//The parameter of this method is $sql is the result of SQL statement execution
{
$this->r=mysql_fetch_array ($sql);
return $this->r;
}
Executive Fetchone (Mysql_fetch_array ())
The difference between this method and fetch () is: 1, the parameter of this method is $query is the SQL statement
2, this method is used while (), the for () database pointer does not automatically move down, and fetch () can be automatically moved down.
function Fetch1 ($query)
{
$this->sql= $this->query ($query);
$this->r=mysql_fetch_array ($this->sql);
return $this->r;
}
Execute mysql_num_rows ()
function num ($query)//The parameter of this class is $query is the SQL statement
{
$this->sql= $this->query ($query);
$this->num=mysql_num_rows ($this->sql);
return $this->num;
}
Executive Numone (Mysql_num_rows ())
The difference between this method and Num () is: 1, the parameter of this method is $sql is the execution result of the SQL statement.
function Num1 ($sql)
{
$this->num=mysql_num_rows ($sql);
return $this->num;
}
Executive Numone (Mysql_num_rows ())
Number of statistical records
function Gettotal ($query)
{
$this->r= $this->fetch1 ($query);
Return $this->r[' Total '];
}
Execute free (mysql_result_free ())
The parameter of this method is $sql is the result of the execution of the SQL statement. Used only in the case of Mysql_fetch_array
function free ($sql)
{
Mysql_free_result ($sql);
}
Execute Seek (Mysql_data_seek ())
The parameter of this method is $sql is the result of the execution of the SQL statement, $pit the offset of the execution pointer
function Seek ($sql, $pit)
{
Mysql_data_seek ($sql, $pit);
}
Execution ID (mysql_insert_id ())
function LastID ()//Get last execution MySQL database ID number
{
$this->id=mysql_insert_id ();
return $this->id;
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.