Welcome Guest, Not a member yet? Register   Sign In
Codeigniter3 + sql 2008
#1

(This post was last modified: 05-04-2015, 06:34 AM by monomicho.)

Hello
I use Codeigniter 3 + Sql Server 2008
I use PHP5.4  + Apache
I use SQLSRV + Microsoft ODBC Driver 11
I cant connect using this code:

PHP Code:
$sn "localhost";
$ci = array('Database'=>'test');
$cn sqlsrv_connect($cv$ci);

if (
$cn)
echo 
"Conexion ok";
else
echo 
"Conexion bad"

Bad when i use codeigniter to connect, it crash
Error: sqlsrv_driver line 144

Help please.
Reply
#2

You probably need to install the Microsoft SQL Server Driver for PHP. See the PHP manual for more information: http://php.net/manual/en/book.sqlsrv.php
Reply
#3

(05-05-2015, 08:12 AM)mwhitney Wrote: You probably need to install the Microsoft SQL Server Driver for PHP. See the PHP manual for more information: http://php.net/manual/en/book.sqlsrv.php

Thanks, but i install the Microsoft SQL Server Driver (sqlsrv and pdo_sqlsrv dlls) and wiich a basic script it work but wich codeigniter dosn't. here the config and the error:

Error:

A PHP Error was encountered
Severity: Error
Message: Maximun execution time of 120 seconds excceded
Filename: sqlsrv/sqlsrv_driver.php
Line Number: 144


My application->config->database look like this

'dsn' => '',
'hostname' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => 'test',
'dbdriver' => 'sqlsrv',[/code]
Reply
#4

You may want to try setting values for 'pconnect', 'char_set', and 'encrypt'. As far as I can tell, these are the only keys the sqlsrv_driver is checking other than those you already have in your config. Another possibility would be to change the 'hostname' to '127.0.0.1'.

Since the line you're getting the error message on is just the call to sqlsrv_connect(), it should be straight-forward to replicate it in an external script to test the values provided in the driver:

PHP Code:
<?php

// $db array from config/database.php.
$db = array(
 
   'hostname' => '',
 
   'username' => '',
 
   'password' => '',
 
   'database' => '',
 
   'pconnect' => false,
 
   'char_set' => 'utf8',
 
   'encrypt'  => false,
);

$charset in_array(strtolower($db['char_set']), array('utf-8''utf8'), TRUE)
 
   'UTF-8' SQLSRV_ENC_CHAR;

$connection = array(
 
   'UID'                  => empty($db['username']) ? '' $db['username'],
 
   'PWD'                  => empty($db['password']) ? '' $db['password'],
 
   'Database'             => $db['database'],
 
   'ConnectionPooling'    => ($db['pconnect'] === TRUE) ? 0,
 
   'CharacterSet'         => $charset,
 
   'Encrypt'              => ($db['encrypt'] === TRUE) ? 0,
 
   'ReturnDatesAsStrings' => 1
);

// If the username and password are both empty, assume this is a
// 'Windows Authentication Mode' connection.
if (empty($connection['UID']) && empty($connection['PWD'])) {
 
   unset($connection['UID'], $connection['PWD']);
}

$conn_id sqlsrv_connect($db['hostname'], $connection);

echo 
$conn_id === false 'Connection error' 'Connection succeeded'
Reply




Theme © iAndrew 2016 - Forum software by © MyBB