This PHP database connection class should be regarded as the simplest connection class, and it is also the best connection class to understand. As a starting point for starting the PHP programming journey. I have read a lot of MYSQL database connection classes circulated on the Internet. It’s all too complicated. In my opinion, there is really no need to make it so complicated, a small database connection.
The following is the class I wrote:
Class createdb //The beginning of the class
{
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"; //Executed mysql
var $row; //Result set Data
function createconn() //This class method starts a conn connection and then starts to select 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 ; ;//Call class connection
$bb->getresule(); //Call class to get the result set
while($bb->getrow()){ //Call class to create pointer to read forward and loop to read data,
echo($bb->row["voteid"]);
echo($bb->row["vote"]);
}
?>
This is written as it is, not optimized. However, it can be used after debugging. In the future, I will continue to write a few more tutorial classes, such as file uploading or other things, to teach you step by step.
There are also css+div layout tutorials and examples, and in the future I will also I will teach you slowly. In fact, making a website is really tiring
There are so many things to learn.
The above introduces the database connection PHP object-oriented usage tutorial simple database connection, including the content of database connection. I hope it will be helpful to friends who are interested in PHP tutorials.