I am trying to connect to a SQL Server (MSSQL) database with PHP. I activated the DBO plugin and am trying to use it, but when I define the object and run the code I get the error: Connection failed: could not find driver
. As you can see from my code, I have verified that the dbo driver is loaded.
I downloaded the sqlsrv driver linked to in one of the answers but I still cannot connect. What am I missing? (the two files index.php
and submit.php
are in the same directory and that is the whole project) ((I am on a Windows computer, but this may or may not be relevant))
index.php:
<html>
<head>
</head>
<body>
<form class="my-form" action="submit.php">
<input type="text" name="field" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
submit.php:
<html>
<head>
</head>
<body>
<h1>page loaded</h1>
<h1><?php if (extension_loaded('pdo')) {
echo 'pdo extension loaded by php';
} ?></h1>
<?php
$myServer = "xxxxxxxxxxxxxxxx";
$myUser = "xxxxxxx";
$myPass = "xxxxxx";
$myDB = "xxxxxxxxxxxx";
$serverName = $myServer; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>$myDB, "UID"=>$myUser, "PWD"=>$myPass);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
</body>
</html>