Database connection and setup procedures

Source: Internet
Author: User

<?phpclass mysql{
Private $host; Server address
Private $name; User name
Private $pass; Password
Private $table; Connect to the Database tutorial
Private $jiema; Set decode
Private $ztime; Set the time zone of the server
constructor function
function __construct ($host, $name, $pass, $table, $jiema, $ztime) {
$this, host = $host;
$this, name = $name;
$this pass = $pass;
$this, table = $table;
$this-Jiema = $jiema;
$this-ztime = $ztime;
$this, connect ();
}
database connections and Settings
function Connect () {
[email protected]_connect ($this->host, $this->name, $this->pass) or Die ("Connection Server failed");
@mysql_select_db ($this->table, $link) or Die ("Connection data failed");
@mysql_query ("Set names ' $this->jiema '");
@date_default_timezone_set ("$this->ztime");
}
Perform actions
function query ($sql) {
if (! ( $query = @mysql_query ($sql)) $this->show ($sql);
return $query;
}
Display information
Function Show ($message = ', $sql = ') {
if (! $sql) echo $message;
else echo $message. ' <br> '. $sql;
}
Get a value for a dataset
function result ($query, $row, $values) {2881064151
Return @mysql_result ($query, $row, $values);
}
Get a value for a dataset
function Get_values ($table, $row, $values) {
$query = Query ("SELECT * from $table"), $this
$returnvalues = mysql_result ($query, $row, $values);
return $returnvalues;
}
Number of rows to get data set
function Num_rows ($query) {
Return @mysql_num_rows ($query);
}
Looping through data
function Fetch ($query) {
Return @mysql_fetch_array ($query);
}
ID value of the last inserted record
function insert_id () {
return mysql_insert_id ();
}
To get a row in the data set
function Fetch_row ($query) {
Return mysql_fetch_row ($query);
}
Insert a piece of data
function Fn_insert ($table, $name, $value) {
if ($this->query ("INSERT into $table ($name) VALUES ($value)")) {
return true;
}else{
return false;
}
}
Insert arbitrary data
function Sql_insert ($tbname, $postvalues) {
foreach ($postvalues as $key = = $value) {
$postvalue. = "'". $key. " `".",";
$sqlvalue. = "'". $value. "',";
}
$sqlfield = Mb_substr ("$postvalue", 0,-1, ' GBK ');
$sqlvalue = Mb_substr ("$sqlvalue", 0,-1, ' GBK ');
if ($this-Fn_insert ("$tbname", "$sqlfield", "$sqlvalue")) {
return true;
}else{
return false;
}
}
modifying universal Data
function Sql_update ($table, $postvalues, $wwhere) {
foreach ($postvalues as $key = = $value) {
$sqlfield. = $key. " = "." "." $value. "'". ",";
}
$sqlfield = Mb_substr ("$sqlfield", 0,-1, ' GBK ');
if ($this->fn_update ("$table", "$sqlfield", "$wwhere")) {
return true;
}else{
return false;
}
}
Modify a piece of data
function Fn_update ($table, $value, $wwhere) {
if ($this->query ("Update $table set $value where $wwhere")) {
return true;
}else{
return false;
}
}
Delete a piece of data
function Sql_delete ($table, $wwhere) {
if ($this->query ("Delete from $table where $wwhere")) {
return true;
}else{
return false;
}
}
Turn off data connections
function Close () {
return Mysql_close ();
}
}
$db = new MySQL ($location [' Host '], $location [' hostname '], $location [' Hostpass '], $location [' table '], $location [' Jiema '], $location [' ztime ']);
?>

Database connection and setup procedures

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.