How to Connect MySQL Database with PHP Websites
You might have heard developers usually speaking of database, they are referring to MySQL, a highly popular DBMS that can power projects of all sizes.
With PHP, you can connect to and manipulate databases.MySQL is the most popular database system used with PHP.
There are three types of methods in PHP to connect MySQL database through backend:
What is MySQL?
MySQL is a database management system used on the web. MySQL is a database system that runs on a server. It is ideal for both small and large applications and is very fast, reliable, and easy to use. it also uses standard SQL (Structured Query Language) use in communicating with the database.
The data in a MySQL database are stored in tables. A table is a collection of related data, and it consists of columns (Vertical) and rows (Horizontal).
Databases are useful for storing information categorically.
In this article, I work you through connecting to our database called mydb using PHP procedural style.
The idea of procedural style is to break down a programming task into a collection of variables, data structures, and subroutines.
- Connect MySQL using Localhost Server
STEP 1): Create Your Database called "mydb" or whatever you wanna call it.
After running the above SQL statement above, you should have your database created in your PHPMyAdmin area.
STEP 2): Create Database Connection File In PHP.
After creating our database, we have to ensure we are connected to our DB, to perform any operation with our database. to do that open up or create a new file in your htdocs folder called dbh.php. After doing that write or paste the below code and run it.
Now open up your web browser and locate your file by going to localhost/dbyh.php, after running this command you should see a text saying "Connected" else you if there's an error, you should see an error message saying "Not Connected".
And that how you connect to a database in MYSQLI using PHP.
For reference, watch
If you enjoy reading this, please consider putting it in the comment below or consider sharing these post.
0 Comments