PDOException错误 [英] PDOException Error
问题描述
你好!我正在做一个非常简单的网页项目.我正在使用phpStorm编写代码,并使用Azure托管SQL,但是当我尝试通过localhost访问站点时,出现以下错误:
Hello! I'm working on a very simple webpage project. I'm using phpStorm to write code and Azure to host the SQL, but when I try to access the site via localhost I get the following error:
连接到SQL Server时出错.PDOException对象([message:protected] =>找不到驱动程序[string:Exception:private] = > [代码:受保护的] => 0 [文件:受保护的] => C:\ Users \ Zachg \ assignment-001 \ my-project \ public \ config.php [line:protected] => 13 [trace:Exception:private] => Array([0] => Array([file] => C:\ Users \ Zachg \ assignment-001 \ my-project \ public \ config.php [line] => 13 [function] => __construct [类别] => PDO [类型] =>-> [args] =>数组 ([0] => sqlsrv:server = tcp: userrequest.database.windows.net ,1433;数据库= userrequest_db [1 ] => Zach [2] => {Grafton1234}))[1] =>数组([file] => C:\ Users \ Zachg \ assignment-001 \ my-project \ public \ index.php [line] => 9 [args] =>数组([0] => C:\ Users \ Zachg \ assignment-001 \ my-project \ public \ config.php)[function] => include))[previous:Exception:private] => [errorInfo] => )1
Error connecting to SQL Server.PDOException Object ( [message:protected] => could not find driver [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\Users\Zachg\assignment-001\my-project\public\config.php [line:protected] => 13 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\Users\Zachg\assignment-001\my-project\public\config.php [line] => 13 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => sqlsrv:server = tcp:userrequest.database.windows.net,1433; Database = userrequest_db [1] => Zach [2] => {Grafton1234} ) ) [1] => Array ( [file] => C:\Users\Zachg\assignment-001\my-project\public\index.php [line] => 9 [args] => Array ( [0] => C:\Users\Zachg\assignment-001\my-project\public\config.php ) [function] => include ) ) [previous:Exception:private] => [errorInfo] => ) 1
这里似乎是所有要引用的代码,它们位于一个名为config.php的文件中:
Here is all the code it seems to be referring to, which is located in a file called config.php:
<?php/** * Created by PhpStorm. * User: Zachg * Date: 9/24/2018 * Time: 2:01 AM */// PHP Data Objects(PDO):try { $conn = new PDO("sqlsrv:server = tcp:userrequest.database.windows.net,1433; Database = userrequest_db", "Zach", "{Grafton1234}"); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);}catch (PDOException $e) { print("Error connecting to SQL Server."); die(print_r($e));}// SQL Server Extension:$connectionInfo = array("UID" => "Zach@userrequest", "pwd" => "{Grafton1234}", "Database" => "userrequest_db", "LoginTimeout" => 30, "Encrypt" => 1, "TrustServerCertificate" => 0);$serverName = "tcp:userrequest.database.windows.net,3306";$conn = sqlsrv_connect($serverName, $connectionInfo);
如果我注释掉"include("config.php")网站就很好了.
if I comment out "include("config.php") the website loads just fine.
任何帮助将深深感激!!
Any help would be so deeply appreciated!! Thank you so much.
推荐答案
Hello,
https://github .com/MicrosoftDocs/azure-docs/blob/master/articles/sql-database/sql-database-firewall-configure.md
https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/sql-database/sql-database-firewall-configure.md
Hope this helps.
Regards,
Alberto Morillo
SQLCoffee.com
这篇关于PDOException错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!