Introduction
There are various ways of connecting to MySQL database using php.
- MySQLi Object-oriented
- MySQLi Procedural
- PDO
Whenever there are multiple way of doing same thing. We get confuse becasue now we have to make a right selection. This is pretty sure that every method must have their own advantage and dis-advanteges.
You can refer to this article where I discussed about the advantage and dis-advantages of all these 3 available methods.
How databse connection works
In simple words database connection is method of sending commands of the database Server and receiving the response from the databse server.
A Database connection is a facility in computer science that allows client software to talk to database server software, whether on the same machine or not. A connection is required to send commands and receive answers. Wikipedia
To connect with the database we need three things.
- Server Name
- Database User Name
- Database Password
- Server Name : In a server/machine php is installed and you want to make request to mysql then you need to specify the servername of MySQL server.
- Database User Name : Specify the username which is available in the database server.
- Database Password : Specify the password crosspoding to the database user.
Default username is
root
and there is no password for the root user.
If MySQL is installed in the same server/machine in which php is installed then you can use servername as
localhost
.
MySQLi Object-oriented
Code for creting database using php in MySQL.
|
|
MySQLi Procedural
Code for creting database using php in MySQL.
|
|
PDO
Code for creting database using php in MySQL.
|
|
You feedback can help you in getting better content from us. Do share you feedback