This repository provide DDEV add-on for a Microsoft SQL Server 2019 db.
In DDEV addons can be installed from the command line using the ddev get
command, for example, ddev get ddev/ddev-db-mssql
.
- this discussion for a good base configuration How to install the SQL Server PHP drivers in DDEV-Local
- this discussion for fix of sqlsrv and pdo_sqlsrv in php Error when installing sqlsrv and pdo_sqlsrv in php8+ apache docker image #1438
this repo provide a:
- docker-compose.db-mssql.yaml service based on
mcr.microsoft.com/mssql/server:2019-latest
- web-build updated configuration adding
sqlsrv
andpdo_sqlsrv
to the default PHP config (see Dockerfile.mssql and install_sqlsrv.sh)
- add the add-on to your DDEV project using
ddev get ddev/ddev-db-mssql
- restart with
ddev restart
- please wait for the build of the updated
web-build
- add a simple test PHP like the MS provided for Testing Your Installation replacing the
${DDEV_SITENAME}
from your project - add
omit_containers: [db]
to your .ddev/install.yaml to omit the default db instance
<?php
$serverName = "ddev-DDEV_SITENAME-db-mssql"; # ddev-${DDEV_SITENAME}-db-mssql
$connectionOptions = array(
"database" => "master",
"uid" => "sa",
"pwd" => "belloQuesto100",
"Encrypt" => false,
"TrustServerCertificate"=>false
);
function exception_handler($exception) {
echo "<h1>Failure</h1>";
echo "Uncaught exception: " , $exception->getMessage();
echo "<h1>PHP Info for troubleshooting</h1>";
phpinfo();
}
set_exception_handler('exception_handler');
// Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die(formatErrors(sqlsrv_errors()));
}
// Select Query
$tsql = "SELECT @@Version AS SQL_VERSION";
// Executes the query
$stmt = sqlsrv_query($conn, $tsql);
// Error handling
if ($stmt === false) {
die(formatErrors(sqlsrv_errors()));
}
?>
<h1> Success Results : </h1>
<?php
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo $row['SQL_VERSION'] . PHP_EOL;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
function formatErrors($errors)
{
// Display errors
echo "<h1>SQL Error:</h1>";
echo "Error information: <br/>";
foreach ($errors as $error) {
echo "SQLSTATE: ". $error['SQLSTATE'] . "<br/>";
echo "Code: ". $error['code'] . "<br/>";
echo "Message: ". $error['message'] . "<br/>";
}
}
?>
Contributed and maintained by @CONTRIBUTOR based on the original ddev-contrib recipe by @CONTRIBUTOR
**Originally Contributed by somebody in https://github.com/ddev/ddev-contrib/