Welcome Guest, Not a member yet? Register   Sign In
Codeigniter 4 not working with sqlsrv
#1
Sad 

Hey guys, I'm trying to connect codeigniter 4 with sqlsrv driver, but it's not working. I'm using wamp server 64. I did all needed configurations.
a) I downloaded drivers for 7.4 php version and
added the "extension=" lines in php.ini file for these two files (php_pdo_sqlsrv_74_ts_x64.dll, php_sqlsrv_74_ts_x64.dll).
b) I checked the php_info and its everything ok.
c) I did a test using the code below and it worked, but when I use the same setting in codeigniter 4, it doesn't work.

PHP Code:
$serverName "DSSQLM01"//serverName\instanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"DW""UID"=>"SA""PWD"=>"v8d2Sa5Y&cq%","Encrypt"=>false,"TrustServerCertificate"=>false);
$conn sqlsrv_connect$serverName$connectionInfo);

if( 
$conn ) {
    echo "Connection established.<br />";
}else{
echo 
"<pre>";
    echo "Connection could not be established.<br />";
    die( print_rsqlsrv_errors(), true));
echo 
"</pre>";
}

$tsql "SELECT * FROM DW WHERE dt_ultima_atualizacao IS NOT NULL";

if((
$result sqlsrv_query($conn,$tsql)) !== false){
    while( $obj sqlsrv_fetch_object$result )) {
          echo $obj->nome.'<br />';
    }


## setting in codeigniter 4
PHP Code:
public $dw = [
 
'DSN'      => '',
'hostname' => 'DSSQLM01'dfasdf,
 
'username' => 'SA',
 
'password' => 'v8d2Sa5Y&cq%',
 
'database' => 'DW',
 
'DBDriver' => 'sqlsrv',
 
'DBPrefix' => '',
 
'pConnect' => false,
 
'DBDebug'  => (ENVIRONMENT !== 'production'),
 
'charset'  => 'utf8',
 
'DBCollat' => 'utf8_general_ci',
 
'swapPre'  => '',
 
'encrypt'  => false,
 
'compress' => false,
 
'strictOn' => false,
 
'failover' => [],
 
'port'    => 1433,
 ]; 


[Image: hWUhen.png]

## Configurações ##
[Image: hWUIfV.png]
Reply
#2

I want to ask you to test the following.
In the system/Database/SQLSRV/Connection.php file, add a backslash to the beginning of all functions starting with sqlsrv_.
Like this sqlsrv_configure => \sqlsrv_configure
And then try to connect to the database.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB