PHP database operation Helper class complete instance, phphelper. PHP database operation Helper class complete instance, phphelper this article describes the PHP database operation Helper class. For your reference, we will share the following details: php database operations are divided into several PHP database operations complete examples of Helper class, phphphelper
This example describes the Helper class for PHP database operations. We will share this with you for your reference. The details are as follows:
Php database operations are divided into several steps (MYSQL is used as an example here ):
1. establish a connection
$connection=mysql_connect($db_host,$db_username,$db_password);
2. select a database
$db_select=mysql_select_db($db_database);
3. execute the CRUD operation
Mysql_query ("set names 'utf8'"); // code $ result = mysql_query ($ sqlstring );
(Mysql_affected_rows () number of records affected by the previous mysql operation)
4. query
mysql_fetch_array($result);mysql_fetch_row($result);
5. close the connection
mysql_close($connection);
DBHelper. php files:
<? Phpclass DBHelper {// establish the connection function GetConnection ($ db_host, $ db_username, $ db_password) {$ connection = mysql_connect ($ db_host, $ db_username, $ db_password ); if ($ connection = false) die ("database connection failed :". mysql_error (); // enter the specific error message return $ connection;} // select the corresponding database function DBSelect ($ db_database) {$ db_select = mysql_select_db ($ db_database ); if ($ db_select = false) die ("database selection failed :". mysql_error (); return $ db_select;} // execute C RUD operation function Excute ($ sqlstring) {$ result = mysql_query ($ sqlstring); return $ result;} // release the resource function CloseConnection ($ connection) {if ($ connection! = Null) mysql_close ($ connection) ;}}?>
Dbtext. php configuration file:
<?php$db_host="localhost";$db_database="mymessage";$db_username="root";$db_password="123456";?>