PHP object-oriented Use tutorial Simple database connection _php Basics

Source: Internet
Author: User
This PHP database connection class, should be considered as the simplest of a connection class, it's also the best way to understand a connection class. As a starting point for the start of the PHP programming journey. I saw a lot of internet circulating MySQL database connection classes, are too complex pull. In my opinion, there is no need to make it so complicated. A small database connection.
Here is my writing class:


<?php
The start of Class Createdb//Classes
{
var $db = "localhost";//database address;
var $dbname = "root";//user name;
var $dbpwd = "";//password;
var $dbtable = "text";//Database used
var $conn; database connection;
var $result; Result set
var $mysql = "Select * from Text"; Execution of MySQL
var $row; Result set Find data
function Createconn ()//The 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;

}

End of the}//class to begin invoking the class to read MySQL database data.
$BB = new Createdb; Class instantiation
$BB->createconn ();//Call the connection of the class
$BB->getresule (); The calling class gets the result set
while ($bb->getrow ()) {//Call class creation pointer read the data forward and iterate,

Echo ($bb->row["Voteid"]);
Echo ($BB->row["vote"]);

}
?>


This is written, not optimized. However, the debugging can be used. Later I will continue to write a few more tutorials class, want to file upload or other, step-by-step teaching everyone.
There are css+div layout tutorials and examples, and then I will slowly teach you. Actually do the website is really very tired
Too many things to learn.

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.