7

I am trying to code CodeIgniter authentication, but when I try, I make an error like this

A Database Error Occurred

Error Number: 1046

No database selected

SELECT * FROM (user) WHERE user_username = 'amanda' AND user_passwordMD5("12345") =

Filename: C:\xampp\htdocs\codeigniter\system\database\DB_driver.php

Line Number: 330

My database.php file:

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = 'authtentication';
$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;
2
  • can you please make sure you have setup database configuration in config/database.php file Commented Apr 5, 2014 at 6:08
  • Please refer to the Codeignitor documentation before jumping to the coding. Commented Apr 5, 2014 at 6:13

4 Answers 4

3

please make sure you have setup database configuration in application/config/database.php file

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'my_database';
Sign up to request clarification or add additional context in comments.

3 Comments

thx, I have tried it and then appear again error like this A Database Error Occurred Unable to select the specified database: authtentication Filename: C:\xampp\htdocs\codeigniter\system\database\DB_driver.php Line Number: 140
Please check your MySql Server it's running?
Make sure your database is exists
2

Check the database.php file in application/config/

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'mypassword';
$db['default']['database'] = 'my_database'; // here is the database selection

3 Comments

I have tried it and then appear again error like this A Database Error Occurred Unable to select the specified database: authtentication Filename: C:\xampp\htdocs\codeigniter\system\database\DB_driver.php Line Number: 140
have you specified the db on database.php
$db['default']['hostname'] = 'localhost'; $db['default']['username'] = ''; $db['default']['password'] = ''; $db['default']['database'] = 'authtentication'; $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; sorry
0

Open the file application/config/database.php file and change the following line:

$db['default']['dbdriver'] = 'mysql';

To:

$db['default']['dbdriver'] = 'mysqli';

This shift to mysqli saved by day.

Comments

-1
$config['hostname'] = "localhost";
$config['username'] = "username";
$config['password'] = "password";
$config['database'] = "database";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.