2

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
EugenSunic
  • 13,162
  • 13
  • 64
  • 86
  • this might be of your interest http://stackoverflow.com/questions/5953882/connecting-to-mssql-using-pdo-through-php-and-linux – DirtyBit Aug 25 '15 at 12:18
  • @HawasKaPujaari look at the edit, I've tried that already... – EugenSunic Aug 25 '15 at 12:33
  • You should search for php folder! There is your php.ini – MozzieMD Aug 25 '15 at 12:37
  • @MozzieMD, I've searched "everywhere" and could not find it in VS-2015. – EugenSunic Aug 25 '15 at 12:39
  • Use windows search! Is your localhost hosted by VS-2015? Maybe you use some apache server like xampp? – MozzieMD Aug 25 '15 at 12:41
  • @MozzieMD I'll give some feedback, I found it via windows search -.- – EugenSunic Aug 25 '15 at 12:46
  • Is it in Program Files? )))) If no, you can check the PHP Tools website, [http://docs.devsense.com/#configuring-php](http://docs.devsense.com/#configuring-php) – MozzieMD Aug 25 '15 at 12:47
  • @MozzieMD the line is uncommented by default, yes it was in program files -.-, do you have any idea what to try next? – EugenSunic Aug 25 '15 at 12:52
  • 1
    try uncommenting sqlsrv instead! If it's not there, then i would recommend going to the page i gave you and do some configurations or even reinstall php with a newer version! – MozzieMD Aug 25 '15 at 12:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87892/discussion-between-mozziemd-and-eugen-sunic). – MozzieMD Aug 25 '15 at 13:32
  • Can you connect to the database from another app or a udp file? – Toby Allen Aug 25 '15 at 16:33
  • @TobyAllen, still nothing, I can't connect neither way, I've looked at instructions at everything. I've also tried on several online php compilers and again same error. – EugenSunic Aug 25 '15 at 16:42
  • If you can't connect with a udp file then you haven't installed the mssql client on your machine. Php is irrelevant to your problems. Good debugging practice never assume anything. – Toby Allen Aug 25 '15 at 16:54

1 Answers1

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

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • Unfortunately this isn't the issue, I've tried to connect to the database via sql server management studio and the connection succeeded. – EugenSunic Aug 25 '15 at 17:43
  • Do you have Microsoft pdo drivers installed – Toby Allen Aug 25 '15 at 17:44
  • I'm reinstalling things including those drivers... I'll respond as quickly as I can. – EugenSunic Aug 25 '15 at 17:54
  • The drivers were the problem. Tnx, I hate annoying people at stack.., am not familiar with php so I'm getting use to it. I thought this came installed already with the package. – EugenSunic Aug 25 '15 at 18:05