Project structure:
Operation effect;
conn.php
Copy Code code as follows:
<?php
Class connectionmysql{
Host
Private $host = "localhost";
Username of the database
Private $name = "root";
Password of the database
Private $pass = "";
Database name
Private $table = "phptest";
Encoded form
Private $ut = "Utf-8";
Constructors
function __construct () {
$this->ut= $ut;
$this->connect ();
}
Links to databases
function Connect () {
$link =mysql_connect ($this->host, $this->name, $this->pass) or Die ($this->error ());
mysql_select_db ($this->table, $link) or Die ("No Database:". $this->table);
mysql_query ("SET NAMES ' $this->ut '");
}
function query ($sql, $type = ') {
if (!) ( $query = mysql_query ($sql)) $this->show (' Say: ', $sql);
return $query;
}
Function Show ($message = ', $sql = ') {
if (! $sql) echo $message;
else echo $message. ' <br> '. $sql;
}
function Affected_rows () {
return Mysql_affected_rows ();
}
function result ($query, $row) {
Return mysql_result ($query, $row);
}
function Num_rows ($query) {
Return @mysql_num_rows ($query);
}
function Num_fields ($query) {
Return Mysql_num_fields ($query);
}
function Free_result ($query) {
Return Mysql_free_result ($query);
}
function insert_id () {
return mysql_insert_id ();
}
function Fetch_row ($query) {
Return mysql_fetch_row ($query);
}
Function version () {
return Mysql_get_server_info ();
}
function Close () {
return Mysql_close ();
}
Inserting values into the $table table
function Fn_insert ($table, $name, $value) {
$this->query ("INSERT into $table ($name) value ($value)");
}
Deletes a record from the table $table based on the $id value
function Fn_delete ($table, $id, $value) {
$this->query ("Delete from $table where $id = $value");
echo "ID is". $id. "The record was successfully deleted!";
}
}
$db = new Connectionmysql ();
$db->fn_insert (' Test ', ' id,name,sex ', ' "', ' hongtenzone ', ' M ');
$db->fn_delete (' Test ', ' id ', 1);
?>