The example in this article describes the PHP database manipulation helper class. Share to everyone for your reference, as follows:
The PHP operations database is divided into several steps (here, for example, MySQL):
1. Establish a connection
$c
2. Select a database
$db _select=mysql_select_db ($db _database);
3. Performing CRUD Operations
mysql_query ("Set names ' UTF8 '");//Encode $result=mysql_query ($sqlstring);
(Mysql_affected_rows () the number of record lines affected by the previous MySQL operation)
4. Enquiry
Mysql_fetch_array ($result); mysql_fetch_row ($result);
5. Close the connection
Mysql_close ($connection);
dbhelper.php class file:
<?phpclass dbhelper{ //Establish connection function getconnection ($db _host, $db _username, $db _password) { $c if ($c die ("Database connection failed:". Mysql_error ());//Enter a 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; } Perform crud operation function Excute ($sqlstring) { $result =mysql_query ($sqlstring); return $result; } Frees 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";? >
More interested in PHP related content readers can view this site topic: "PHP based on PDO operation database Tips Summary", "PHP+MONGODB Database operation Skills Daquan", "PHP Object-oriented Programming tutorial", "PHP String Usage Summary", " Php+mysql database Operation Tutorial "and" PHP common database Operation Skills Summary "
I hope this article is helpful to you in PHP programming.
The above describes the PHP database Operation helper Class complete example, including the helper aspects of the content, I hope that the PHP tutorial interested in a friend helpful.