PHP object-oriented user guide simple database connection

Source: Internet
Author: User
PHP object-oriented usage tutorial simple database connection to the PHP database connection class should be regarded as the simplest connection class, it is also the best to understand a connection class. 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

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.