简体   繁体   English

php5.4 sqlite3 PDO

[英]php5.4 sqlite3 PDO

I've read all around, there is no clear answer what is the difference between: 我已经阅读了很多,没有明确的答案之间的区别是什么:

$db = new SQLite3('/directory/file.db');
$db = new SQLite('/directory/file.db');
$db = new PDO('sqlite:/directory/file.sqlite');

from what I can tell there is no difference between the bottom two? 从我可以看出来,最下面的两个之间没有区别吗? I'm trying to use the best solution for PDO with sqlite3 我正在尝试使用带有sqlite3的PDO最佳解决方案

thanks. 谢谢。

Basically, those are 3 different extensions for handling databases. 基本上,这些是用于处理数据库的3个不同的扩展。

SQLite version 3 has changed so much, it needed new driver. SQLite版本3发生了很大变化,它需要新的驱动程序。 So SQLite3 library was created. 因此创建了SQLite3库。

SQLite is when you want to use SQLite databases older than version 3. 当您要使用版本3之前的SQLite数据库时,可以使用SQLite。

PDO is library, that allows you changing of Database driver without touching your code. PDO是库,它使您无需更改代码即可更改数据库驱动程序。

Basically, when using PDO you don't write SQL queries, but create query objects. 基本上,使用PDO时,您无需编写SQL查询,而是创建查询对象。 Those generate query dependent on currently selected database. 它们根据当前选择的数据库生成查询。 Allowing you to smoothly change database. 让您顺利地更改数据库。

http://www.php.net/manual/en/book.pdo.php http://www.php.net/manual/zh/book.pdo.php

http://www.php.net/manual/en/book.sqlite.php http://www.php.net/manual/zh/book.sqlite.php

http://www.php.net/manual/en/book.sqlite3.php http://www.php.net/manual/zh/book.sqlite3.php

$db = new SQLite3('/directory/file.db');

That's the SQLite3 extension, see here: http://php.net/SQLite3 . 这是SQLite3扩展,请参见此处: http : //php.net/SQLite3

$db = new PDO('sqlite:/directory/file.sqlite');

That's the PDO extension with the sqlite driver, also for SQLite3 databases. 这是sqlite驱动程序的PDO扩展,也适用于SQLite3数据库。 See http://php.net/manual/en/ref.pdo-sqlite.php . 参见http://php.net/manual/en/ref.pdo-sqlite.php

If you like PDO's interface, this is nice. 如果您喜欢PDO的界面,那就太好了。 Otherwise, SQLite3 is fine too. 否则, SQLite3也可以。 See https://stackoverflow.com/a/10703665/476 for what the difference between PDO and other extensions are. 有关PDO和其他扩展之间的区别,请参见https://stackoverflow.com/a/10703665/476

$db = new SQLite('/directory/file.db');

This is: 这是:

In PHP 5.1, the SQLite extension also provides a driver for SQLite 2 databases; 在PHP 5.1中,SQLite扩展还提供了SQLite 2数据库的驱动程序。 while it is not technically a part of the PDO_SQLITE driver, it behaves similarly, so it is documented alongside it. 尽管从技术上讲,它不是PDO_SQLITE驱动程序的一部分,但其行为类似,因此在它的旁边进行了说明。 The SQLite 2 driver for PDO is provided primarily to make it easier to import legacy SQLite 2 database files into an application that uses the faster, more efficient SQLite 3 driver. 提供PDO的SQLite 2驱动程序主要是为了使其更容易将旧版SQLite 2数据库文件导入使用更快,更高效的SQLite 3驱动程序的应用程序中。 As a result, the SQLite 2 driver is not as feature-rich as the SQLite 3 driver. 结果,SQLite 2驱动程序不像SQLite 3驱动程序那样功能丰富。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM