Connect to SQL SERVER - php

i want to connect to sql server
my php version is 5.4 and i have MS SQL Server 2008 R2 and i use PHP Codeigniger 2.4
i change database.php config
$db['default']['hostname'] = '192.168.5.208';
$db['default']['username'] = 'xxx';
$db['default']['password'] = 'xxx';
$db['default']['database'] = 'xxx';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
i download sqlsrv30.exe.
install it in php/ext
i add the following on the php.ini file:
extension=php_sqlsrv_54_ts.dll
i install Native Client 10
i change sqlsrv_driver.php in folder database-driver-sqlsrv to
function db_pconnect() {
//return $this->db_connect(TRUE);
return $this->db_connect(TRUE);
}
i also try add
db['default']['port'] = 1433;
but its still not working. I always encountered the ff. error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\HRM\system\database\DB_driver.php
Line Number: 124
what should i do ? please help

this solves it
change $db['default']['db_debug'] = TRUE; to $db['default']['db_debug'] = FALSE;
and
change $db['default']['pconnect'] = TRUE; to $db['default']['pconnect'] = FALSE;

Related

Unable to select the specified database: conection to localhost (PHP with MySQL) in windows 10

I've been trying to connect to my database so I can make some changes in a website, in a local way, not directly on the server. But I always come to this error:
"Unable to select the specified database: backup"
. It says that the problem is in the file:
Filename: C:\xampp\htdocs\system\database\DB_driver.php
Line Number: 141.
But this is what I have in the line:
$this->display_error('db_unable_to_select', $this->database);
My script is like this:
$db['default']['username'] = 'teste';
$db['default']['password'] = '123456';
$db['default']['hostname'] = 'localhost';
$db['default']['database'] = 'backup';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = 'tbl_';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I changed the name of the driver, but it didn't work as well.
the line of code that try to select the db:
function db_select()
{
return #mysqli_select_db($this->database, $this->conn_id);
}
How to proceed?

SQL Server 2008 R2 and Code Igniter Connection

I am using windows 8 and am trying to use sqlserver 2008 as my database.
I installed sql driver (SQLSRV31.exe) and I have
php_sqlsrv_54_ts.dll
php_sqlsrv_55_ts.dll
php_sqlsrv_54_nts.dll
php_sqlsrv_55_nts.dll
php_pdo_sqlsrv_54_ts.dll
php_pdo_sqlsrv_55_ts.dll
php_pdo_sqlsrv_54_nts.dll
php_pdo_sqlsrv_55_nts.dll
extracted to my php/ext. I have made changes to php.ini as
extension=php_pdo_sqlite.dll
extension=php_sqlsrv.dll
extension=php_sqlsrv_54_ts.dll
extension=php_pdo_sqlsrv_54_ts.dll
Similarly,this is my database configuration
$db['default']['hostname'] = "127.0.0.1";
$db['default']['port'] = 1433;
$db['default']['username'] = 'sa';
$db['default']['password'] = '**';
$db['default']['database'] = 'db_test';
$db['default']['dbdriver'] = 'sqlsrv';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
But I keep on getting error as Fatal error:
Call to undefined function sqlsrv_connect() in
C:\xampp\htdocs\test\system\database\drivers\sqlsrv\sqlsrv_driver.php on line 76.
Could anyone please helpme with this?

Connection to remote mysql from localhost

I have searched the net to no solution for a problem I am facing.
I am working on a codeigniter project which I am running on a localhost Apache Server. For the database, I am attempting to connect from CI's database.php configuration file to connect to a remote server.
The following is my configuration
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'remotedatabase.com';
$db['default']['username'] = 'remote_2102Dev';
$db['default']['password'] = '1q2w3e4r5t';
$db['default']['database'] = 'remote_cs2102';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I have tried to connect to the remote Database via mysql workbench 5.5. So that means I have did the configuration correctly at the server side.
Please help me. Is this CI problem or there is something wrong with my settings. Thank you.
Check host entry # remotedatabase.com. It should be % in host
If your PHP version is >= 5.3 set db_debug to false:
$db['default']['db_debug'] = FALSE;

Connect to IBM DB2 from Codeigniter

I have never worked with DB2 before. I am trying to connect from codeigniter. I have used the following settings in my database config file:
$db['default']['hostname'] = 'ipAddress';
$db['default']['port'] = 'portNumber';
$db['default']['username'] = 'uname';
$db['default']['password'] = 'pword';
$db['default']['database'] = 'myDBName';
//$db['default']['dbdriver'] = 'pdo';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
and it throws the following error:
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\archive\system\database\DB_driver.php
Again, I am totally new to DB2, so in case I need to install anything extra (I assume the driver is already included in my latest CI download) or I need to define a dsn (please let me know how to do that if i require that) please do let me know, will very much appreciate your help.
Yes, you need to install the IBM Data Server Client package, or at least Runtime Client. Download the appropriate driver from http://www-01.ibm.com/support/docview.wss?uid=swg27016878
The manual explains how to configure DB2 access from a PHP application.
You need to add the full connection to the hostname parameter , as the following code
$active_group = 'default';
$active_record = FALSE;
$db['default']['hostname'] = "driver={IBM db2 odbc DRIVER};Database=DBNAME;hostname=localhost;port=50000;protocol=TCPIP;" . "uid=username; pwd=password";
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'DBNAME.SCHEMANAME';
$db['default']['dbdriver'] = 'odbc';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

CodeIgniter issue with database

I am following a beginner's tutorial for CodeIgniter, but I can't get the view to load correctly because I have a database connection error. I have followed everything step-by-step, and gone through it again several times, but not been able to fix it. Could someone please help me, or at least explain why this is happening?
Here is the database configuration I currently have setup:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'helloworld';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
I've also autoloaded the database library with the following code:
$autoload['libraries'] = array('database');
I would also like to point out that I am using PHP version 5.3.13. I not sure if the version of PHP would affect my code, so I added it anyway.
The exact error I'm getting is:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\wamp\www\CI\system\database\DB_driver.php
Line Number: 124
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root'; // default username if has not been set in phpmyadmin
$db['default']['password'] = ''; //leave it blank if has not been set in phpmyadmin
$db['default']['database'] = 'helloworld'; // this is your database name
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
you might have tried to import the project to work space.Instead try to traverse to the project folder through project explorer

Categories