CodeIgniter REST Api log on separated DB 20 seconds more - mysql

I have a REST Api Codeigniter server which respond very well. 0.02 sec max per call.
I want to enable the logs but when i do it, responses take 20 more secondes. So 20.02 seconds for the same process.
I found that the time is lost in REST_Controller.php file at this line :
$this->rest->db = $this->load->database($this->config->item('rest_database_group'), TRUE);
When the rest DB is loaded.
My Database file have 2 DB records like this :
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
//'dsn' => '',
'hostname' => 'X.X.X.X',
'username' => 'my_user',
'password' => 'my_pass',
'database' => 'my_database',
'dbdriver' => 'mysqli',
'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
);
$db['rest'] = array(
//'dsn' => '',
'hostname' => 'X.X.X.X',
'username' => 'my_user',
'password' => 'my_pass',
'database' => 'my_database',
'dbdriver' => 'mysqli',
'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
);
And my config file have $config['rest_database_group'] = 'rest';
The log line is written in the rest database without any problems but 20 seconds more than without logs...
Any ideas?
Thks for your help.
David.

Thks for your help. I found the solution.
There was a DNS Problem on my MySQL Server. Just talk with IP addresses is not enougth. I had to specify my Server's names in hosts files on each server.
The lag time of 20 seconds was on the MySQL SQL there was a login trying of a unauthenticated user from my server.
Problem is gone with DNS parms.
Bye !

Related

Server IP address cannot be found using XAMPP

I am trying to load my website using XAMPP but receive the following error message.
This website was built using code ignitor and has been placed inside the htdcos folder of xampp.
Below is a screenshot of the XAMPP control panel.
Furthermore, below is a screenshot of my htdcos folder.
The file name is media.einnovation.com.
Below is a screenshot of the media.einnovation sub folder.
From here I tried to load the website from the index of my local host. I have also tried https://localhost/media.einnovation.com and it still does not work.
Below is the database.php file confiugration for the website.
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'einnoven_media1',
'dbdriver' => 'mysqli',
'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
);
Would anyone happen to know what the issue is?

How to connect mysql database from the diffarent server to localhost xampp in codeigniter

I have to connect database from my domain example (www.test.com) to other project on localhost xampp thought codeigniter platform.
I have tried below code in aplication/config/database.php
Note: I have not mentioned exact host name, database, username & password for security reasons.
$db['default'] = array(
'dsn' => '',
'hostname' => 'XXX.XX.XX.XXX:3306',
'username' => '****_cs_user',
'password' => '********',
'database' => '****_case_study',
'dbdriver' => 'mysqli',
'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
);
You need to ensure that this options are correctly filled:
$db['default'] = array(
'dsn' => '',
'hostname' => 'yourhostip',
'username' => 'yourmysluser',
'password' => 'yourmysqlpassword',
'database' => 'yourdb',
'dbdriver' => 'mysqli',
'port' => '3306'
// Rest of options
);
According to the Codeigniter documentation, you can separate the port from the hostname.
You should make sure that in your server is activated the remote access, by default is disabled. Check this post to enable this feature.

Loading databases dynamically in codeigniter

My application uses Codeigniter 3.X and I'm trying to use different DBs for each of my user.
So the main db is main_db and if a user with user id 1 logs in then I want to use db_1 and so on.
Codeigniter allows me to use multiple DBs but I want to achieve this dynamically.
Is there a way to load DBs dynamically in codeigniter? If yes then how?
I have included my database.php below and I load the database in model construct as
$this->load->database();
database.php
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'username',
'password' => 'password',
'database' => 'main_db',
'dbdriver' => 'mysqli',
'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
);

Codeigniter no connect in database

My error >>>
An uncaught Exception was encountered
Type: ParseError
Message: syntax error, unexpected '<', expecting end of file
Filename: C:\wamp64\www\application\config\database.php
Line Number: 97
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'sistema', // your database name
'dbdriver' => 'mysqli',
'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
);
?>
complete code https://pastebin.com/us3mycVT
Remove the ?> at the end of that file.
Here you can find more information on why you shouldn't close the php tags on those files.
Why would one omit the close tag?
Looked at the original file sent by the user. Basically there was a hidden character in the file. Created a new database.php with original encoding and everything worked fine.

Code Igniter : A Database Error Occurred SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

I'm trying to upload a website to the server. Code Igniter is framework that I 've used for this site and I'm using CI for the first time. While trying to upload the website to the server with following database setiings:
$db['default'] = array(
'dsn' => 'mysql:host=localhost;dbname=database_name',
'hostname' => 'mysql:host=localhost',
'username' => 'database_user',
'password' => 'database_password',
'database' => 'database_name',
'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've been getting errors as follows and I tried to search the net for solving my issues. I found some issues which were similar to mine but I can't figure out what I should be doing because most of the issues were for local servers. Please could someone help me out to solve it thanks.
A Database Error Occurred
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
Filename: controllers/Home.php
Line Number: 9
A PHP Error was encountered
Severity: Warning
Message: PDO::__construct(): The server requested authentication method unknown to the client [mysql_old_password]
Filename: pdo/pdo_driver.php
Line Number: 133
Backtrace:
Edit:
Try:
$db['default'] = array(
'hostname' => 'localhost',
'username' => 'user',
'password' => 'password',
'database' => 'database_name',
'dbdriver' => 'mysqli',
'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
);
or
$db['default'] = array(
'dsn' => 'mysql:host=localhost;dbname=codeigniter',
'username' => 'codeigniter',
'password' => 'codeigniter',
'database' => 'codeigniter',
'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
);
You can use this code for database setting in database.php
$active_group = 'live';
$active_record = TRUE;
$db['live']['hostname'] = 'localhost';
$db['live']['username'] = 'user';
$db['live']['password'] = 'password';
$db['live']['database'] = 'database';
$db['live']['dbdriver'] = 'pdo';
$db['live']['dbprefix'] = '';
$db['live']['pconnect'] = TRUE;
$db['live']['db_debug'] = TRUE;
$db['live']['cache_on'] = FALSE;
$db['live']['cachedir'] = '';
$db['live']['char_set'] = 'utf8';
$db['live']['dbcollat'] = 'utf8_general_ci';
$db['live']['swap_pre'] = '';
$db['live']['autoinit'] = TRUE;
$db['live']['stricton'] = FALSE;
Set $config["useDatabaseConfig"] = true; in your config.php
I hope it will work for you.