Introduction to PHP database interfaces and technologies
1. Which databases are supported by php (which database interfaces are available)
Adabas D, InterBase, PostgreSQL, dBase, Front base, SQLite, Empress, mSQL, Solid, FilePro (read-only), Direct MS-SQL, Sybase, Hyperwave, MySQL, Velocis, IBM DB2, ODBC, unix dbm, informix, Oracle (OCI7 and OCI8), Ingres, Ovrimos
All the above databases are supported. In short, most mainstream databases are supported.
2. php native mysql Database Operation Method
<? Php // Database Operations // 1. import database require (".. /.. /public/dbconfig. php "); // 2. connect to database $ link = mysql_connect (HOST, USER, PASS) or die ("database connection failed"); // 3. select a database and set the character set mysql_select_db (DBNAME, $ link); mysql_set_charset ("utf8"); // 4. write an SQL statement and send it 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 >{$ us Er ['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. PDO concept of php
PDO is a PHP Data Object. It uses data as an object to improve the security and convenience of operation data. It is supported in PHP5.1, for example, prepared statements), bound parameters, scrollable cursors, positioned updates, and LOB.
DAO (Data Access Object) is an Object-oriented (PDO) database interface. In many PHP frameworks, it forms a secure and convenient Data processing interface through the native PDO encapsulation, the DAO method in YII is as follows:
Http://www.yii-china.com/doc/guide/db_dao.html
<? Php> // configure the db in conponents of the advanced \ common \ config \ main-local.php; // connect to the database $ connection = Yii: $ app-> db; // compile the pre-processing query statement $ command = $ connection-> createCommand ('select * FROM Post'); // execute the operation $ posts = $ command-> queryAll (); $ post = $ command-> queryOne (); $ titles = $ command-> queryColumn (); <? Php>
4. Active Record
ActiveRecord is a design pattern. Its direct purpose is not to operate a database, but a data model. It is a more advanced abstraction of data than DAO. It provides a unified object-oriented interface,
Used to access data in the database.
Use AR to simplify code and reduce the possibility of errors. The following example shows the AR Operation Method in YII.
// Instantiate the customer object of the data table $ customer = new Customer (); $ customer-> name = 'qiang '; $ customer-> save (); // Insert a new row of data into the customer table
5. When will DAO or AR be used?
Use DOA for complex business logic, and AR for reverse
The above discussion about the PHP database interface and technology is a small part of the Content shared to everyone, I hope to give you a reference, but also hope you can support a lot of help homes.