Home  >  Article  >  Backend Development  >  Summary of content about php database interface technology

Summary of content about php database interface technology

伊谢尔伦
伊谢尔伦Original
2017-07-03 09:38:271405browse

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=&#39;center&#39;>";
echo "<td>{$userstate[$user[&#39;state&#39;]]}</td>";
echo "<td>{$user[&#39;username&#39;]}</td>";
echo "<td>".date("Y-m-d",$user[&#39;addtime&#39;])."</td>";
echo "<td>
<a href=&#39;edit.php?id={$user[&#39;id&#39;]}&#39;>修改</a> 
<a href=&#39;action.php?a=del&id={$user[&#39;id&#39;]}&#39;>删除</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(&#39;SELECT * FROM post&#39;);
//执行操作
$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 = &#39;Qiang&#39;;
$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn