Home » Open Source » MySQL » Connecting to MSSQL server via php-pdo? (10g)
Connecting to MSSQL server via php-pdo? [message #658464] Thu, 15 December 2016 02:18 Go to next message
keyto
Messages: 1
Registered: December 2016
Junior Member
I'm unable to connect to MSSQL database on asphostportal 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

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



--moderator update: post approved, and moved to the MySQL forum. jw.

[Updated on: Thu, 15 December 2016 02:51] by Moderator

Report message to a moderator

Re: Connecting to MSSQL server via php-pdo? [message #659428 is a reply to message #658464] Mon, 16 January 2017 11:18 Go to previous message
ThomasG
Messages: 3205
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
Shouldn't that MYSQL in the PDO Connect string to connect to MySQL? MSSQL would be the Microsoft SQL Server
Previous Topic: MySQL text book
Next Topic: JSON extract
Goto Forum:
  


Current Time: Wed Dec 13 05:31:55 CST 2017

Total time taken to generate the page: 0.01394 seconds