0

I currently have a web server set up on DigitalOcean that i work from, i've been creating various web apps and now i need to use php to connect to a database hosted by Microsoft Azure, it uses PDO

try {
$conn = new PDO("sqlsrv:server = tcp:NAME.database.windows.net,1433; Database = DATABASE", "USERNAME", "PASS");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
    print("Error connecting to SQL Server.");
    echo 'ERROR: ' . $e->getMessage();
    die(print_r($e));
}

And this is the result:

Error connecting to SQL Server.ERROR: could not find driverPDOException Object ( [message:protected] => could not find driver [string:Exception:private] => [code:protected] => 0 [file:protected] => /var/www/html/angularv3/leon3.php [line:protected] => 3 [trace:Exception:private] => ... 

Now i've opened up the console and typed the following to make sure it's all installed

sudo apt-get install php5-mysql

and still nothing, there must be something major i'm missing. Is it possible to connect to an azure database from anywhere?

mekk33
  • 130
  • 1
  • 9
  • 1
    Not sure what database you are using, you say "MySQL" but the connection string (`sqlsrv:server ...`) is for SQL Server. – Aaron Chen Jan 20 '17 at 02:07
  • @AaronChen-MSFT i was sent that from my supervisor that set up a microsoft azure database, i have no idea how to connect to that database with my basic html/php setup – mekk33 Jan 20 '17 at 08:27
  • See this answer: http://stackoverflow.com/questions/41624704/sql-server-pdo-could-not-find-driver/. – Aaron Chen Jan 20 '17 at 09:23

1 Answers1

2

You have to add the module pdo_mysql and restart apache

sudo apt-get update
sudo apt-get install pdo-mysql php5-mysql

If after this you are unable to use the extension you can check your /etc/php5/apache2/php.ini and make sure it includes:

extension=pdo.so
extension=pdo_mysql.so

And restart apache:

sudo service apache2 restart

Note: Commands can be different depends on linux distribution, php version and apache version.

Leandro Papasidero
  • 3,728
  • 1
  • 18
  • 33
  • I've done both and still no change :/ is there a way to set this all up locally? – mekk33 Jan 19 '17 at 15:00
  • Sure you can. I am not sure what you exactly mean about "is there a way". have you ever installed linux before? If you are a Microsoft guy have you installed wamp or xampp. – Leandro Papasidero Jan 19 '17 at 17:46
  • im currently working on mac, I have a lunix server on my personal hosting service but id have to develop this all locally and find a way to deploy it after. – mekk33 Jan 20 '17 at 09:12
  • Some people uses mamp on mac. I personally use vagrant (virtual box) and for deployment CodeDeoploy in AWS or Git Webhooks in other hosting. Good luck with your project! Btw, try to contact DigitalOcen support, they might help you with your PDO error – Leandro Papasidero Jan 20 '17 at 12:50