1. What databases are supported by PHP (which database interfaces are available)
Adabas D, InterBase, PostgreSQL, DBase, Frontbase, SQLite, Empress, MSQL, Solid, Filepro (Read only), Direct Ms-sql, Sybase, Hyperw Ave, MySQL, Velocis, IBM DB2, ODBC, Unix dbm, Informix, Oracle (OCI7 and OCI8), Ingres, Ovrimos
The above databases are supported, in short, to support the vast majority of mainstream databases
2. PHP Native operation MySQL Database method
<?php//database Operation//1. Import database require (".. /.. /public/dbconfig.php ")//2. Connect to Database $link=mysql_connect (Host,user,pass) or Die (" database connection Failed ");//3. Select the database, set character sets Mysql_ select_db (DBNAME, $link), Mysql_set_charset ("UTF8"),//4. Writing SQL statements, sending SQL statements to the database $sql= "SELECT * from users"; $res =mysql_ Query ($sql, $link);//5. Parse result set while ($user =mysql_fetch_assoc ($res)) {echo "<tr align= ' center ' >"; echo "<td> {$userstate [$user [' state ']]}</td>; Echo ' <td>{$user [' username ']}</td> '; Echo ' <td> '. Date ( "Y-m-d", $user [' Addtime ']). " </td> "echo" <td><a href= ' edit.php?id={$user [' id ']} ' > Modify </a> <a href= ' Action.php?a=del &id={$user [' id '} ' > Delete </a></td> '; Echo ' </tr> ';} Mysql_free_result ($res); Mysql_close ($link);? >
3. The PDO concept of PHP
PDO, a PHP data object, operates on data as an object, improving the security and convenience of operational data, starting with support from the PHP5.1 version, such as preprocessing statements (prepared statements), binding parameters (bound parameters), Scrollable cursors (scrollable cursors), location updates (positioned updates), and lobs.
The DAO data Access object is an object-oriented (PDO) database interface that forms a secure and convenient data processing interface for native PDO encapsulation in many PHP frameworks
<?php>//configuration of db;//Connection database in advanced\common\config\main-local.php conponents $connection = Yii:: $app->db;// Write a preprocessing query statement $command = $connection->createcommand (' SELECT * from post ');//Perform Operation $posts = $command->queryall (); $post = $command->queryone (); $titles = $command->querycolumn ();<?php>
4. Active record
ActiveRecord is a design pattern whose direct purpose is not to manipulate the database, but rather a data model, which is a more advanced abstraction of the data than DAO. It provides an object-oriented unified interface,
Used to access data in the database.
Using AR's larger simplified code reduces the likelihood of error, the following example is the AR operation method in Yii
Data table Customer Object Instantiation $customer = new Customer (); $customer->name = ' Qiang '; $customer->save (); Insert a new row of data into the Customer table
5, when the use of DAO or AR
Complex business logic uses DOA instead of AR