Trying to connect my CodeIgniter 4.5.1 project to a SQL Server (14.0) database. Running on Windows with XAMPP, PHP version 8.2.
I downloaded the appropriate DLLs from Microsoft, put them in my PHP extensions folder and enabled the extensions
In my .env file I entered the database information:
PHP Code:
database.default.hostname = "MYSERVER\TEST"
database.default.database = 'mydb'
database.default.username = 'myuser'
database.default.password = 'mypassword'
database.default.DBDriver = 'sqlsrv'
I get the following error:
Code:
Unable to connect to the database.
Main connection [sqlsrv]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: Der Wartevorgang wurde abgebrochen.
SQLSTATE: 08001, code: 258
The server is running and the credentials are correct (I triple-checked).
If I connect to the DB the "hard" way (using the same credentials), it works just fine (just dropped code below into my controller):
PHP Code:
$serverName = "MYSERVER\TEST";
$uid = "myuser";
$pwd = "mypassword";
$databaseName = "mydb";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$databaseName);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$tsql = "SELECT id, name FROM users";
$stmt = sqlsrv_query( $conn, $tsql);
if ( $stmt )
{
echo "Statement executed.<br>\n";
}
else
{
echo "Error in statement execution.\n";
die( print_r( sqlsrv_errors(), true));
}
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))
{
echo "Col1: ".$row[0]."\n";
echo "Col2: ".$row[1]."\n";
echo "-----------------<br>\n";
}
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
I am probably just doing something incredibly stupid, but I have been staring at this for hours and I am at my wit's end. Anyone have an idea? Thank you for reading.