Welcome Guest, Not a member yet? Register   Sign In
SQL server connection not working
#1

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_rsqlsrv_errors(), true));  
        
}  
              
        
while( $row sqlsrv_fetch_array$stmtSQLSRV_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.
Reply


Messages In This Thread
SQL server connection not working - by falagar2k - 04-24-2024, 02:31 AM
RE: SQL server connection not working - by kenjis - 04-24-2024, 05:44 PM
RE: SQL server connection not working - by kenjis - 04-25-2024, 12:54 AM
RE: SQL server connection not working - by kenjis - 04-25-2024, 04:31 AM
RE: SQL server connection not working - by kenjis - 04-25-2024, 03:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB