ADODB 到 PDO 快速切换

发布于 2024-08-20 03:09:45 字数 87 浏览 3 评论 0原文

过去我在 php 中使用 adodb 作为 mysql。现在,我想使用 PDO。有什么方法可以让我使用一个数据库连接快速从 adodb 查询切换到 pdo 吗?

In past i use adodb for mysql in php. Now, i want to use PDO. Is there any way that for me to quick switch from adodb query to pdo using one connection to datebase?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初吻给了烟 2024-08-27 03:09:45

您可能需要检查以下两个示例:

#PDO script:
$db = new PDO("mysql:dbname=you_db_name;host=127.0.0.1", "root", "");
$rs = $db->query("SELECT * FROM table")->fetchAll(PDO::FETCH_ASSOC);
foreach($rs as $r) {}

#ADOdb script
require_once("adodb5/adodb.inc.php");
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$db = NewADOConnection("mysql://root:@127.0.0.1/you_db_name");
$rs = $db->Execute("SELECT * FROM table");
foreach($rs as $r) {}

请注意,PDO 是本机编译的库,不会在运行时加载。

You may want to check the following two examples:

#PDO script:
$db = new PDO("mysql:dbname=you_db_name;host=127.0.0.1", "root", "");
$rs = $db->query("SELECT * FROM table")->fetchAll(PDO::FETCH_ASSOC);
foreach($rs as $r) {}

#ADOdb script
require_once("adodb5/adodb.inc.php");
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$db = NewADOConnection("mysql://root:@127.0.0.1/you_db_name");
$rs = $db->Execute("SELECT * FROM table");
foreach($rs as $r) {}

Note that PDO is a native compiled library and not loaded at runtime.

美胚控场 2024-08-27 03:09:45
<?php
class Config
{
    private $host = "localhost";
    private $user =  "root";
    private $password =  "";
    private $dbname =  "php_crud";

    public function connect(){

        $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
        $pdo =  new PDO($dsn,$this->user,$this->password);
        $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
        return $pdo;
    }
}
?>
<?php
class Config
{
    private $host = "localhost";
    private $user =  "root";
    private $password =  "";
    private $dbname =  "php_crud";

    public function connect(){

        $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
        $pdo =  new PDO($dsn,$this->user,$this->password);
        $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
        return $pdo;
    }
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文