Home >Backend Development >PHP Tutorial >Summary of content about php database interface technology
1. Which databases does PHP support (which database interfaces does it have)
Adabas D, InterBase, PostgreSQL, dBase, FrontBase, 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
The above databases are supported. In short, Supports most mainstream databases
2, PHP native operation method of mysql database
<?php //数据库操作 //1.导入数据库 require("../../public/dbconfig.php"); //2.连接数据库 $link=mysql_connect(HOST,USER,PASS) or die("数据库连接失败"); //3.选择数据库,设置字符集 mysql_select_db(DBNAME,$link); mysql_set_charset("utf8"); //4.编写sql语句,发送sql语句到数据库 $sql="select * from users"; $res=mysql_query($sql,$link); //5.解析结果集 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']}'>修改</a> <a href='action.php?a=del&id={$user['id']}'>删除</a> </td>"; echo "</tr>"; } mysql_free_result($res); mysql_close($link); ?>
3, PDO of PHP Concept
PDO is PHP data object. It operates data as an object, which improves the security and convenience of operating data. It is supported starting from PHP5.1 version, such as prepared statements ( prepared statements), bound parameters, scrollable cursors, positioned updates, and LOBs.
DAO (Data Access Object) Data Access Object is an object-oriented (PDO) database interface. In many PHP frameworks, a safe and convenient data processing interface method is formed by encapsulating the native PDO
<?php> //在advanced\common\config\main-local.php的conponents中配置好db; //连接数据库 $connection = Yii::$app->db; //编写预处理查询语句 $command = $connection->createCommand('SELECT * FROM post'); //执行操作 $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 the database, but a data model. Relative to DAO, it is a higher-level abstraction of data. It provides a unified object-oriented interface to access data in the database.
Use AR to simplify the code and reduce the possibility of errors. The following example is the AR operation method in YII
//数据表customer对象实例化 $customer = new Customer(); $customer->name = 'Qiang'; $customer->save(); // 一行新数据插入 customer 表
5. When to use DAO or ARComplex business logic uses DOA, otherwise use AR
The above is the detailed content of Summary of content about php database interface technology. For more information, please follow other related articles on the PHP Chinese website!