codeigniter - cannot connect to MySQL database - php

Error that is getting printed out
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346
I have been looking through all the other questions and nothing seems to work. Still getting this error. All the info in my database.php file matched up to my info on the mysql server that I am running on the command line. I am also using mysqld and mysql.server start. I have tested the connection on the command line with
mysql -h localhost -uroot -p dbname
And that seems to work on my command line, but it is giving me the error above when I am referencing it on a localhost server I have set up with the codeigniter project. What am i doing wrong? I have double and triple checked naming conventions to make sure that it isn't the issue.
Also, I am on OS X Mavericks
my code in the config file is as follows:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'PASS';
$db['default']['database'] = 'dbname';
$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 run into this problem frequently myself with CodeIgniter. The usual solution (for me!) is to set 'pconnect' and 'db_debug' to FALSE:
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;

I tried to change the following line in my config/database.php file and it worked. (The error your getting means something is wrong with your config/database.php)
'hostname' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Explanation for this behaviour is written here (MySQL on OSX finds mysql.sock wrongly).
Cheers!

Related

Remote database connection in codeigniter

I have 2 server A (Code) and B (Database). I need to access (connect) A to B. I am using mysql 5.6 phpmyadmin and php running in ubuntu 14.04. All I know is that i need to whitelist a user in phpmyadmin. Since I am new to this, can anyone guide me on this.. I have made changes in database.php in server A as follow
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'IP of Server B';
$db['default']['username'] = 'abc';
$db['default']['password'] = '123';
$db['default']['database'] = 'db1';
$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;
After doing this change when i run the my server A the following error pops up
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338
I have even edited /etc/mysql/my.cnf in server B by binding the server's IP.
bind_ip=[Server B IP]
I can not comment so I'll just add it here, first of all, make sure you can access your database server remotely. Under normal circumstances port 3306 will be blocked.
Once all the proper credentials are given in database.php, we need to comment out bind-address=1270.0.1 in /etc/mysql/my.cnf file of Server B. Before that stop mysql and restart it once the editing is done.

PHP error connecting to MS SQL 2005 using CodeIgniter

I'm encountering an error every time I'm connecting to my MS SQL 2005 database using CodeIgniter framework, I'm using PHP 5.6.8 version.`
"Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp\htdocs\my_website\system\database\drivers\sqlsrv\sqlsrv_driver.php
on line 76"
I've already added dll files php_pdo_sqlsrv_56_ts.dll and php_sqlsrv_56_ts.dll to ext folder and on my php.ini, and installed Microsoft SQL Native Client 2012,
this is my code in the sqlsrv_driver.php line 76 -> return sqlsrv_connect($this->hostname, $connection);
I already setup and installed all needed files but still I encounter this error, and NO sqlsrv in phpinfo(), so I created a sample php file to test if I will connect to my database w/out using a framework and its successfully connected in MS SQL database, However it doesn't if I used codeigniter.
Did I miss some code, configuration or software to install? Thanks for usual support!
This is my database.php
$db['default']['hostname'] = 'MY-PC\MSSQL2005';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'password';
$db['default']['database'] = 'MYDB';
$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;

CodeIgniter 2.2.1 and Xampp 5.5.19 Not Connecting to Database

I was previously using Xampp 1.8.2 and CodeIgniter 2.2.1 connecting to MSSQL 2012. My database configuration was working well and fine until i moved to xampp 5.5.19 and using the same database configuration. This is how i did it:
I downloaded respective Microsoft drivers for PHP for SQL server (php_sqlsrv_5ts.dll) and copied it to the ext folder in the php installation folder. I then updated my php.ini file to load this extension. I also configured my MSSQL co listen to a specific port (is used the standard 1433). I then configured my database connection in the config codeigniter folder as follows:
$db['default']['hostname'] = 'CORE14\CORE12';
$db['default']['username'] = 'sa';
$db['default']['password'] = 'sa';
$db['default']['port'] = 1433;
$db['default']['database'] = 'HomoOpes';
$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;
I restarted my server and tried to access my application. I get the error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\TUMHRMS\system\database\DB_driver.php
Line Number: 124
I thought xampp 5.6 was unstable and i uninstalled it because it was bringing the same problem it then installed xamp 5.5.19 and am getting the same problem. Somebody help.
Thank you
try to use odbc driver
$db['mssql']['hostname'] = 'Driver={SQL Server};Server=CORE14\CORE12;Database=HomoOpes';
$db['mssql']['username'] = 'sa';
$db['mssql']['password'] = 'sa';
$db['mssql']['database'] = 'HomoOpes';
$db['mssql']['dbdriver'] = 'odbc';
try to change
$db['default']['dbdriver'] = 'sqlsrv';
to
$db['default']['dbdriver'] = 'mysql';
or
$db['default']['dbdriver'] = 'mysqli';

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;

XAMPP codeigniter Database Error

I face an error when trying the tutorial of CodeIgniter. When I try the "News section". I get the error
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\CI\system\database\DB_driver.php
Line Number: 124
I am using XAMPP and my os is windows7(64 bit).
My details in the C:\xampp\htdocs\CI\application\config\database.php are follows
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'xxx';
$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 succeeded When to establish the connection to db with core php.
Somebody help me to resolve this..
Thanks in advance..
Reset XAMPP and check if phpmyadmin working and database 'xxx' exist.
using phpmyadmin create the database..name it xxx
then try loading the site again
Also check the index.php file in the root folder.
Sometimes people will place code here to change which database file it uses based on the domain.. not sure what codeigniter tutorial you are following.
first make sure you load your database library
$autoload['libraries'] = array('database');
then check your default settings to see whether something is missing using.
echo '<pre>';
print_r($db['default']);
echo '</pre>';
Set db_debug to false in your CI's database.php.
Another tip. When locally everything is very very slow, change localhost to 127.0.0.1.
Kamikaze™ - 08 December 2011 06:39 AM
Is your table name in uppercase? Be careful with lowercase and uppercase, I had the same problem.
Try this: $this->db->get(“PROJECT_USERS”);

Categories