<small id='jM2Fi'></small><noframes id='jM2Fi'>

      <tfoot id='jM2Fi'></tfoot>
      <legend id='jM2Fi'><style id='jM2Fi'><dir id='jM2Fi'><q id='jM2Fi'></q></dir></style></legend>
    1. <i id='jM2Fi'><tr id='jM2Fi'><dt id='jM2Fi'><q id='jM2Fi'><span id='jM2Fi'><b id='jM2Fi'><form id='jM2Fi'><ins id='jM2Fi'></ins><ul id='jM2Fi'></ul><sub id='jM2Fi'></sub></form><legend id='jM2Fi'></legend><bdo id='jM2Fi'><pre id='jM2Fi'><center id='jM2Fi'></center></pre></bdo></b><th id='jM2Fi'></th></span></q></dt></tr></i><div id='jM2Fi'><tfoot id='jM2Fi'></tfoot><dl id='jM2Fi'><fieldset id='jM2Fi'></fieldset></dl></div>
        <bdo id='jM2Fi'></bdo><ul id='jM2Fi'></ul>
    2. PDO 返回错误“找不到驱动程序"使用已知的

      时间:2023-09-19

      <small id='qIbek'></small><noframes id='qIbek'>

          <bdo id='qIbek'></bdo><ul id='qIbek'></ul>
          <legend id='qIbek'><style id='qIbek'><dir id='qIbek'><q id='qIbek'></q></dir></style></legend>
            <tbody id='qIbek'></tbody>
            1. <i id='qIbek'><tr id='qIbek'><dt id='qIbek'><q id='qIbek'><span id='qIbek'><b id='qIbek'><form id='qIbek'><ins id='qIbek'></ins><ul id='qIbek'></ul><sub id='qIbek'></sub></form><legend id='qIbek'></legend><bdo id='qIbek'><pre id='qIbek'><center id='qIbek'></center></pre></bdo></b><th id='qIbek'></th></span></q></dt></tr></i><div id='qIbek'><tfoot id='qIbek'></tfoot><dl id='qIbek'><fieldset id='qIbek'></fieldset></dl></div>

              <tfoot id='qIbek'></tfoot>

                本文介绍了PDO 返回错误“找不到驱动程序"使用已知的 DSN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在尝试通过 php 的 PDO 类连接到 odbc 数据库:

                $dsn = 'odbc:CS_HDZipCodes32bit';$用户名 = '演示';$password = 'skdemo!';$connection = new PDO($dsn, $username, $password);死( var_dump( $connection ) );

                但是当我这样做时,我收到错误:

                <块引用>

                致命错误:在 C:inetpubwwwrootpdoClass.php:7 堆栈跟踪:#0 C:inetpubwwwrootpdoClass.php(7) 中出现消息找不到驱动程序"的未捕获异常PDOException": PDO->__construct('odbc:CS_HDZipCo...', 'demo', 'skdemo!') #1 {main} 在第 7 行的 C:inetpubwwwrootpdoClass.php 中抛出

                $dsn 值是我在 ODBC 管理器中创建的 DSN 的名称.

                我知道这个特定的 DSN 有效,因为我能够构建另一个演示文件并通过 odbc_connect 成功连接:

                $connection = odbc_connect("CS_HDZipCodes32bit", 'demo', 'skdemo!');如果(!$连接){die('连接失败');}$statement = "SELECT * FROM ZipCodes";$result = odbc_exec($connection, $statement);//按预期输出拉链var_dump(odbc_result_all($result));

                我一直在研究

                看起来驱动程序已安装,除非这是不同的驱动程序.

                另一个更新

                根据 Marc B 的附加评论进一步检查我的 phpini,看起来我没有安装 POD ODBC 特定驱动程序:

                这里,如果我安装了 pdo 的 ODBC 驱动程序,odbc 将位于列表的末尾,对吗?

                解决方案

                在最初问题的评论中得到 Marc B 的大力帮助后,结果证明问题出在我对启用 odbc 的误解在我的 Web 服务器上并安装了 pdo_odbc 驱动程序.

                虽然我确实在 Web 服务器上启用了 odbc,但我没有为 PDO 安装 odbc 驱动程序.

                此驱动程序是通过 pdo 访问 odbc 数据库所必需的.

                根据关于

                添加驱动程序并重新启动服务器后,我现在加载了驱动程序:

                并且我在演示数据库上使用 PDO 的测试查询有效:

                $dsn = 'odbc:CS_HDZipCodes32bit';$用户名 = '演示';$password = 'skdemo!';$connection = new PDO($dsn, $username, $password);$query = "从邮政编码中选择 *";$result = $connection->query($query);foreach($result 作为 $row){var_dump($row);}

                转储:

                感谢马克 B 的帮助.

                I'm trying to connect to an odbc database via php's PDO class:

                $dsn = 'odbc:CS_HDZipCodes32bit';
                $username = 'demo';
                $password = 'skdemo!';
                
                $connection = new PDO($dsn, $username, $password);
                
                die( var_dump( $connection ) );
                

                but when I do, I get the error :

                Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:inetpubwwwrootpdoClass.php:7 Stack trace: #0 C:inetpubwwwrootpdoClass.php(7): PDO->__construct('odbc:CS_HDZipCo...', 'demo', 'skdemo!') #1 {main} thrown in C:inetpubwwwrootpdoClass.php on line 7

                The $dsn value is the name of the DSN I created in my ODBC Manager.

                I know this particular DSN works because I was able to build another demo file and connect successfully via odbc_connect:

                $connection = odbc_connect("CS_HDZipCodes32bit", 'demo', 'skdemo!');
                
                if(!$connection){
                    die('connection failed');
                }
                
                $statement = "SELECT * FROM ZipCodes";
                
                $result = odbc_exec($connection, $statement);
                
                
                // Outputs the zips as expected
                var_dump(odbc_result_all($result));
                

                I've been digging through the PDO-ODBC documentation as well as other resources online, but I can't figure out why PHP is unable to find the driver when trying from PDO.

                Any ideas?

                Update

                I popped open my phpinfo page to make sure the odbc driver is installed per Marc B's comment:

                It looks like the driver is installed unless this is a different driver.

                Another Update

                On further inspection of my phpini per Marc B's additional comment, it looks like I don't have the POD ODBC specific driver installed:

                So here, if I had the ODBC driver for pdo installed, odbc would be at the end of the list, correct?

                解决方案

                After getting some great help from Marc B in the initial question's comments it turns out the problem was coming from my misunderstanding of enabling odbc on my web server and having the pdo_odbc driver installed.

                While I did have odbc enabled on the web server, I did not have the odbc driver installed for PDO.

                This driver is necessary to be able to access odbc databases via pdo.

                Per the php.net documentation on installing pdo for windows, the driver was already included in the php build (I'm using version 5.5) and just needed to be included in the php.ini file.

                After adding the driver and restarting the server I now had the driver loaded:

                and my test query using PDO on my demo database worked:

                $dsn = 'odbc:CS_HDZipCodes32bit';
                $username = 'demo';
                $password = 'skdemo!';
                
                $connection = new PDO($dsn, $username, $password);
                
                $query = "Select * FROM ZipCodes";
                
                
                $result = $connection->query($query);
                
                foreach($result as $row){
                    var_dump($row);
                }
                

                Dumps out:

                Thanks for your help Marc B.

                这篇关于PDO 返回错误“找不到驱动程序"使用已知的 DSN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:PDO 的 FETCH_INTO $这个类不起作用 下一篇:PHP 验证文件上传

                相关文章

                最新文章

                <tfoot id='AEzhT'></tfoot>
              • <small id='AEzhT'></small><noframes id='AEzhT'>

              • <i id='AEzhT'><tr id='AEzhT'><dt id='AEzhT'><q id='AEzhT'><span id='AEzhT'><b id='AEzhT'><form id='AEzhT'><ins id='AEzhT'></ins><ul id='AEzhT'></ul><sub id='AEzhT'></sub></form><legend id='AEzhT'></legend><bdo id='AEzhT'><pre id='AEzhT'><center id='AEzhT'></center></pre></bdo></b><th id='AEzhT'></th></span></q></dt></tr></i><div id='AEzhT'><tfoot id='AEzhT'></tfoot><dl id='AEzhT'><fieldset id='AEzhT'></fieldset></dl></div>
              • <legend id='AEzhT'><style id='AEzhT'><dir id='AEzhT'><q id='AEzhT'></q></dir></style></legend>

                    <bdo id='AEzhT'></bdo><ul id='AEzhT'></ul>