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.