Latreso Latreso - 3 months ago 10
MySQL Question

default php mysqli connection in php.ini

I have problem with auto connect to database in php.
I need to configure it using php.ini file or something else.
If i can do this, which the query can i use?

I try to configure it, but it right or wrong?:

mysqli.default_socket=
mysqli.default_host="localhost"
mysqli.default_user="root"
mysqli.default_pw=""
mysqli.reconnect=On


Additional information:

First, i need to hide mysql host, user and password in php code, but not use the include or something.
Secondly, I want to be able to conveniently use.

Answer

I try to configure it, but it right or wrong?

Yes, it's right. You can omit quotes though.

If i can do this, which the query can i use?

Not sure what you ask, but in case you are asking for the connection code, it would be as simple as that:

$db = mysqli_connect();
$db->select_db('test');

Note that you cannot define the database name this way and thus have to set it explicitly using the corresponding function.

Comments