I run wamp and try to connect to db but I got
Unable to connect to your database server using the provided settings.
Few faqs / what I've done:
I autoloaded the database library in config.php
my phpMyAdmin doesn't have any username and pass set
this is the setting in database.php
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => 'ciintro',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'autoinit' => TRUE,
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
'username' => '',
should be
'username' => 'root',
check username.
I think you are newer to codeigniter.
'username' => 'root' ( root or whatever you set for PHPMYADMIN.)
'password' => 'password' ( password or whatever you set for PHPMYADMIN.)
Related
I am hosting a CodeIgniter API on GCP App Engine and I cant connect to the GCP Cloud SQL. I create the instance and database, but when I try to conect via CI I got a timeout message
error screen
My databse config on CI is:
$db['default'] = array(
'dsn' => 'mysql:unix_socket=/instance_name/instancia;dbname=project_name',
'hostname' => 'http://00.000.00.00',//here i put the public ip from the sql instance
'username' => 'user',
'password' => 'passwd',
'database' => 'projeto',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => yes,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I've been banging my head on this for a while, myself, and finally cracked it! Here's what my db config looks like:
$db['default'] = array(
'dsn' => '',
'hostname' => '/cloudsql/PROJECT-NAME:REGION:DATABASE',
'username' => 'USERNAME',
'password' => 'PASSWORD',
'database' => 'DATABASE_NAME',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
// 'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
The important bits are that the dsn is empty and the hostname is the full path to the unix socket. The rest of it should be about the same.
Hope that helps you, too!
I have newly installed PHP 7.2.4 and Apache 2.4 on windows server 2008 r2. Everything done; i have set the paths, but problem is that when i configuring my PHP file for the connection, it gives me an error unable to connect with database. I am using codeIgniter 3.1.8.
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE
)
define('ENVIRONMENT','development'); This is a Codeigniter 3, database.php (non SSPI) snippet example for MSSQL 2008R2:
define('ENVIRONMENT','development');
$db['test1'] = array( 'dsn' => '',
'hostname' => 'MY_MSSQL_DB_FQDN\i1,10001',
'username' => 'somemssqluser',
'password' => 'somemssqlpassword',
'database' => 'somedbname',
'dbdriver' => 'sqlsrv',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I always get the following error in my codeigniter 3 application when I start using a sqlite3 database.
SQLite3::query(): Unable to prepare statement: 1, no such table: pages
I have read somewhere that this is the case when you have the wrong path to the databse. My database is located in application/db/pages.sqlite
This is the config for the sqlite database:
$db['pages'] = array(
'dsn' => '',
'hostname' => '',
'username' => '',
'password' => '',
'database' => APPPATH.'db/pages.sqlite',
'dbdriver' => 'sqlite3',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
What have I done wrong?
Try this, it worked for me before
'database' => 'sqlite:'.APPPATH.'db/pages.sqlite',
Also make sure that folder db is readable by your app.
First you need to check that sqlite3 php module is installed on your web server or not?
This will required to work Codeigniter3 sqlite3 db driver.
If its not working then provide 'dsn' string. This will definitely working.
First thing try to check your php.ini and uncomment this
extension=php_pdo_sqlite.dll
extension=php_sqlite3.dll
and try this
$db['default'] = array(
'dsn' => 'sqlite:application/db/pages.sqlite',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
i have this on my localhost and it works perfectly fine.
but when i put it on a server i configured the database settings correctly
here is my config/database.php
$db['default'] = array(
'dsn' => '',
'hostname' => '111.111.1.111', //sample host
'username' => 'root',
'password' => 'password',
'database' => 'mydatabase',
'dbdriver' => 'mysqli',
'port' => '1234',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => FALSE
);
but all i got was the error
Unable to connect to your database server using the provided settings.
Filename: third_party/MX/Base.php
Line Number: 55
what is the problem?
I am conneting two databases in codeigniter. My database.php configuration is as follows.
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'dvrs',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['orcl_db'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'mvrs',
'password' => 'mvrs',
'database' => 'MVRS',
'dbdriver' => 'oci8',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Now I am autoloading the default database, and loading the orcl_db in the respective model on demand using
$this->orclDB = $this->database->load("orcl_db", TRUE);
I am connecting to both dbs and running queries successfully.
I need to make sure that the oracle server is available before connecting to it and display proper error messages if the server is not available / not responding.
What will be the best way to do this?
Following is the code to ensure it.
$this->orclDB = $this->load->database('orcl_db', TRUE);
if (!$this->orclDB ->initialize()) {
$response["status"] = false;
$response["message"] = "Oracle DB is not available.";
}
In order to turn off db debugging, which throws fatal error when db connection fails, use $db['orcl_db']['db_debug'] = FALSE; in your database config file. Then you can check if database is loaded like this:
if ( $this->load->database('orcl_db') === FALSE )
{
// do whatever you think is appropriate, but do not panick
}