Answer the question
In order to leave comments, you need to log in
How does PHP code understand where the MySQL database is located?
I want to understand how the connection between PHP and MySQL code goes. Let's say I created a config folder in it with a connection file. But how does the connection itself take place, how does the file understand that the database is on the computer?
Answer the question
In order to leave comments, you need to log in
The mysql database by default works through a TCP connection, port 3306. The address (host) 127.0.0.1 or localhost will be specified in the configuration file, which means that we connect to ourselves.
When connecting to the database, you also specify the DSN where the host, database name, login and password.
Connection example from PDO documentation
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$connectionParams = array(
'dbname' => 'mydb',
'user' => 'user',
'password' => 'secret',
'host' => 'localhost',
'driver' => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams);
this guide helped me. everything is perfectly shown in practice. used to transfer data from arduino with a record to the database, followed by output to a web page
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question