Connecting to MSSQL server via php-pdo?

本小妞迷上赌 提交于 2019-12-24 03:41:48

问题


I'm unable to connect to MSSQL database on smarterasp.net domain. I'm using:

PHP Tools for Visual Studio

Here is the code:

<?php
 try {
     $conn = new PDO("mssql:host=host_name_string;dbname=database_name_string", "username_string", "password_string");

     // set the PDO error mode to exception
     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     echo "Connected successfully"; 
 }
 catch(PDOException $e)
 {
     echo "Connection failed: " . $e->getMessage();
 }

?>

and the error caught by the PDOexception class:

Connection failed: could not find driver

I've also tested my code online and again getting the same error(online tester url: http://sandbox.onlinephpfunctions.com).

I've searched for the solution and the only thing that could resolve my problem is by uncommenting:

extension=php_pdo_mysql.dll

but the line is already uncommented by default.

EDIT: The following does not ressolve my problem (instead of mssql:host)

  • sqlsrv:host
  • dblib:host

回答1:


Your problem is that you have not installed either the sql server client or the Microsoft pdo drivers on your machine. Please do that and make sure you can connect via a udp file.

Search SQL server client install and Microsoft pdo drivers



来源:https://stackoverflow.com/questions/32203737/connecting-to-mssql-server-via-php-pdo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!