Skip to content

mattocchi/ddev-db-mssql

Repository files navigation

tests project is maintained

ddev-db-mssql

What is ddev-db-mssql?

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.

Thanks to

Components of the repository

this repo provide a:

Getting started

  1. add the add-on to your DDEV project using ddev get ddev/ddev-db-mssql
  2. restart with ddev restart
  3. please wait for the build of the updated web-build
  4. add a simple test PHP like the MS provided for Testing Your Installation replacing the ${DDEV_SITENAME} from your project
  5. 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/

About

Additional MS Sql Server Service for DDEV

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages