Introduction to PHP database interfaces and technologies

Source: Internet
Author: User
Tags ibm db2 php database import database

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.

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.