PHP Operation MySQL Class!

Source: Internet
Author: User
Tags continue html page insert mysql web hosting
MySQL;?
# All text and code within this file are (c) opyright
# Pangolin Software Limited 2000.
#
# You'll edit this file to customise it for your web-site,
# However, the actual source code may is altered in
# any way without the prior written permission of Pangolin
# Software Limited.
# This file is part of the pangolin Vote distribution.
# contact:pangolin@pango.co.uk or www.pango.co.uk for more info.
/*
* Utility routines for MySQL.
* Modified from Code from:http://www.webwizard.com/tutorials/mysql/
*/
Class Mysql_class {
# Make sure your fill in the ' values below for your web-site.
# They are for User,password,host and database respectively.
#
var $user = "USERNAME";
var $pass = "PASSWORD";
var $thedatabase = "DATABASE";
var $host = "localhost";

var $db, $id, $result, $rows, $data, $a _rows;
/*
* It ' s a minor security hole to have the username and password
* appear here. Generally there isn ' t any way of getting around it
* If you ' re using a commercial web hosting service. There are other
* Ways if it ' s your own Web server.
*/
function Setup ($user, $pass) {
$this->user = $user;
$this->pass = $pass;
}
function Create () {
$db = $this->thedatabase;
$this->db = $db;
$crash = 0;
$this->id = @mysql_pconnect ($this->host, $this->user, $this->pass) or
$crash = 1;
if ($crash ==1) {
Mysql_errormsg ("Unable to connect to MySQL server: $this->host-either your username, password or database values are Incorrect in vutil.php3 or your have not started MYSQL on your web server! ");
Die ("<p>unable to Continue.<p>");
}
$this->selectdb ($DB);
}
function Selectdb ($db) {
$crash = 0;
@mysql_select_db ($db, $this->id) or $crash = 1;
if ($crash ==1)
{
Mysql_errormsg ("Unable to select database: $db: The ' value in Vutil.php3 ' is incorrect.");
Die ("<p>unable to Continue.<p>");
}
}
# Use this function is the query would return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$this->result = @mysql_query ($query, $this->id) or
Mysql_errormsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows ($this->result);
$this->a_rows = @mysql_affected_rows ($this->result);
}
# Use this function if the query would only return a
# Single Data element.
function Queryitem ($query) {
$this->result = @mysql_query ($query, $this->id) or
Mysql_errormsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows ($this->result);
$this->a_rows = @mysql_affected_rows ($this->result);
$this->data = @mysql_fetch_array ($this->result) or mysql_errormsg ("Unable to fetch.");
Return ($this->data[0]);
}
# This function is useful if the query'll only return a
# single row.
function Queryrow ($query) {
$this->result = @mysql_query ($query, $this->id) or
Mysql_errormsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows ($this->result);
$this->a_rows = @mysql_affected_rows ($this->result);
$this->data = @mysql_fetch_array ($this->result) or mysql_errormsg ("Unable to fetch.");
Return ($this->data);
}
function Fetch ($row) {
@mysql_data_seek ($this->result, $row) or mysql_errormsg ("Unable to seek data.");
$this->data = @mysql_fetch_array ($this->result) or mysql_errormsg ("Unable to fetch.");
}
function Insert ($query) {
$this->result = @mysql_query ($query, $this->id) or
Mysql_errormsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows ($this->result);
}
function Update ($query) {
$this->result = @mysql_query ($query, $this->id) or
Mysql_errormsg ("Unable to perform update: $query");
$this->a_rows = @mysql_affected_rows ($this->result);
}
function Delete ($query) {
$this->result = @mysql_query ($query, $this->id) or
Mysql_errormsg ("Unable to perform Delete: $query");
$this->a_rows = @mysql_affected_rows ($this->result);
}
}
/* ********************************************************************
* Mysql_errormsg
*
* Print out a MySQL error message
*
*/
function Mysql_errormsg ($msg) {
# Close out a bunch of HTML constructs which might prevent
# the HTML page from displaying the error text.
Echo ("</ul></dl></ol<\n");
Echo ("</table></script>\n");
# Display the error message
$text = "<font color=\" #ff0000 "><p><b>error: $msg:";
$text. = Mysql_error ();
$text. = "</b></font>\n";
$errormsg = $text;
# get rid of unable to fetch error messages
if (Strpos ($errormsg, "unable to fetch") ==false)
print "$errormsg \ n";
}
?>

Related Article

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.