0

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.

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

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
meda
  • 45,103
  • 14
  • 92
  • 122

1 Answers1

0

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

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

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));
}
meda
  • 45,103
  • 14
  • 92
  • 122
  • Thank you for your reply. this thing is, i'm on Mac and those drivers are available for Windows. Any idea how to resolve this issue? – user3766744 Jun 24 '14 at 13:17
  • @user3766744 well thats the issue, Linux cannot connect to microsoft directly, you will need some driver like FreeTDS. how come you have dlls on linux? – meda Jun 24 '14 at 13:45
  • i'm sorry but i'm confused here. So, i'm supposed to download freeTDS driver and then microsoft driver? I've reading about this issue for the past day and been adding extensions to my php.ini file, those dlls. i guess they didnt help – user3766744 Jun 24 '14 at 13:55
  • Dont get confused, you are trying to connect from a Linux machine to a Microsoft Database server, you need a driver that will allow you to do that, check this http://stackoverflow.com/questions/13371281/how-can-i-connect-to-sql-server-from-a-mac-with-php-pdo – meda Jun 24 '14 at 15:29