Introduction to PHP A class _php technique for connecting MySQL databases

Source: Internet
Author: User

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);
?>

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.