PHP object-oriented user guide simple database connection. This PHP database connection class should be regarded as the simplest connection class, and it is also the best to understand a connection class. as a start to the PHP programming journey. I have read a lot of PHP database connection classes on the Internet, which should be the simplest connection class and the best to understand. as a start to the PHP programming journey. I have read many MYSQL database connection classes circulating on the Internet, which are too complicated. in my opinion, there is really no need to make that complicated, a small database connection.
The following are my written classes:
Class createdb // Class start
{
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"; // mysql executed
Var $ row; // Find data in the result set
Function createconn () // This class method is to start a conn connection, and then start to select a database
{
$ This-> conn = mysql_connect ($ this-> db, $ this-> dbname, $ this-> dbpwd );
Mysql_select_db ($ this-> dbtable, $ this-> conn );
}
Function getresule () // This is 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;
}
} // When the class ends, the class is called to read mysql database data.
$ Bb = new createdb; // class instantiation
$ Bb-> createconn (); // call the connection of the class
$ Bb-> getresule (); // call the class to obtain the result set.
While ($ bb-> getrow () {// call the class to create a pointer to read data in a forward read loop,
Echo ($ bb-> row ["voteid"]);
Echo ($ bb-> row ["vote"]);
}
?>
This is written and not Optimized. However, it can be used after debugging. in the future, I will continue to write several more tutorial classes. if you want to upload files or other files, I will teach you step by step.
There are also css + p layout tutorials and examples, and I will teach you slowly in the days to come. In fact, website preparation is really tiring.
Too many things to learn
...