连接到Microsoft Azure时出现PDO异常错误 [英] PDO Exception error while connecting to microsoft azure

查看:75
本文介绍了连接到Microsoft Azure时出现PDO异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上连接到Azure时遇到问题.我在这里阅读了许多文章,并在php.ini文件中添加了多个扩展名,但似乎没有任何效果.我只想简单地运行此代码并连接到数据库.代码中所有变量的实际值均正确.

i have problem connecting to azure on my mac. I've read many articles here and added multiple extension to my php.ini file but nothing seems to work. I just want to simply run this code and connect to database. All the variables in the code have the actual values are correct.

此刻,它给了我以下错误:"PDOException Object ( [message:protected] => could not find driver".

At the moment it gives me following error : "PDOException Object ( [message:protected] => could not find driver".

我浏览了有关此问题的多篇文章,并为php.ini添加了扩展名.我已经粘贴了以下所有内容供人们检查.我现在也将PDO附加到服务器上.不幸的是,我无法在此处发布快照,但是我的pdo_mysql,pdo_pgsql,pdo_sqlite在phpinfo()调用中.

i've looked throuh mutiple articles on this issue, and added extensions to php.ini. i've pasted all of the below for people to check. i also now that i have PDO attached to my server. Unforunately, i cant post the screemshot here, but my pdo_mysql, pdo_pgsql, pdo_sqlite in the phpinfo() call.

我非常感谢您提供有关此问题的任何信息和帮助.谢谢!

i would really appreciate any info and help on this matter. thank you!

   $server = "tcp:*********.database.windows.net,1433";
   $user = "jus***@********";
   $pwd = "password";
   $db = "testdb";

   try
   {
       $conn = new PDO( "sqlsrv:Server= $server ; Database = $db ", $user, $pwd);
       $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    }

   catch(Exception $e)
   {
      die(print_r($e));
   }


     ;Extensions
     ;extension=apcu.so
     extension=imap.so
     extension=yaz.so
     extension=mcrypt.so
     extension=gettext.so
     extension=pgsql.so
     extension=pdo_pgsql.so
     extension=pdo_mysql.so
     extension=php_pdo.dll
     extension=php_pdo_mysql.dll
     extension=php_pdo.dll
     extension=php_pdo_firebird.dll
     extension=php_pdo_informix.dll
     extension=php_pdo_mssql.dll
     extension=php_pdo_mysql.dll
     extension=php_pdo_oci.dll
     extension=php_pdo_oci8.dll
     extension=php_pdo_odbc.dll
     extension=php_pdo_pgsql.dll
     extension=php_pdo_sqlite.dll 
     ;extension=imagick.so

推荐答案

除了您在php.ini中启用的扩展之外,还需要安装:

In addition to the extensions that you have enabled in php.ini you will need to install:

还必须确保您使用的不是错误的php.ini

You have to also make sure you are not using the wrong php.ini

在连接字符串中避免使用这些空格,如果有任何问题,您应该抓住PDOException.

Avoid these spaces in your connection string, and if you anything you should catch PDOException.

$server = "tcp:*********.database.windows.net,1433";
$user = "jus***@********";
$pwd = "password";
$db = "testdb";
$dsn = "sqlsrv:Server=$server;Database=$db";

try {
   $conn = new PDO($dsn, $user, $pwd );
   $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
} catch (PDOException $e) {
    die(print_r($e));
}

这篇关于连接到Microsoft Azure时出现PDO异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆