Database connection PHP Object-oriented use tutorial simple database connection

Source: Internet
Author: User
Tags php database php database connection class
This PHP database connection class, it should be the simplest of a connection class, but also the best to understand a connection class. As a starting point for starting PHP's programming journey. I saw a lot of internet-based MySQL database connection classes, all too complex to pull. In my opinion, there's really no need to be so complicated, A small database connection.
Here is the class I wrote:

Class Createdb//start of classes
{
var $db = "localhost";//database address;
var $dbname = "root";//username;
var $dbpwd = "";//password;
var $dbtable = "text";//Database used
var $conn; database connection;
var $result; Result set
var $mysql = "Select * from Text"; Executed by MySQL
var $row; Finding data in the result set
function Createconn ()//This class method is to start a conn connection and then start selecting the database
{
$this->conn = mysql_connect ($this->db, $this->dbname, $this->dbpwd);
mysql_select_db ($this->dbtable, $this->conn);
}
function Getresule ()//This is to get a result set
{
$this->result = mysql_query ($this->mysql, $this->conn);
}
function GetRow ()//Create a forward result set pointer
{
$this->row = mysql_fetch_array ($this->result);
return $this->row;
}
The}//class ends and begins invoking the class to read the MySQL database data.
$BB = new Createdb; Class instantiation
$BB->createconn ();//Call the class's connection
$BB->getresule (); Calling a class to get a result set
while ($bb->getrow ()) {//calls the class to create a pointer to read the data ahead of the loop,
Echo ($bb->row["Voteid"]);
Echo ($BB->row["vote"]);
}
?>

This is written well, not optimized. However, debugging is OK to use. I will continue to write a few more tutorial classes, want to file upload or other, step by step teach you.
There are css+div layout tutorials and examples, and then I will slowly teach you in the days to come. Actually doing the website really good tired
Too many things to learn.

The above describes the database connection PHP object-oriented use of the tutorial simple database connection, including the content of the database connection, I hope the PHP tutorial interested in a friend helpful.

  • 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.