How to Connect MySQL using PHP
Hello friends today I am going to show you how to connect to mysql database using PHP code. It is assumed that you have already installed MySQL and are using Apache HTTP Server. Instead of installing all those o stuff individually I prefer using WAMPSERVER.
Also I want to suggest using a smart Text Editor. I prefer using Sublime Text 3 as it is freely available and it can be evaluated for lifetime. It is an easy Text Editor and a multi-purpose as is supports many coding and scripting languages. It is like a All-Rounder.
So here is the code for connection. As you can see I have created Index.php file in which I have used Html for convenience although it is not necessary. The title of my File is Wooble you can use any thing else that you like.
<!DOCTYPE html>
<html lang="en"><head>
<title>Wooble</title>
</head>
<body>
<?php
//Database Connection Creation
$conn_error = 'Could not Connect.';
$db = mysqli_connect('localhost','root','','wooble');
if(mysqli_connect_errno())
{
die($conn_error);
}
else
{
echo 'Connected!';
}
?>
</body>
</html>
For connection I have used mysqli_connect and mysql_connect. If you are using PHP5 then an error might occur as this method is obsolete. The name of the Database is wooble hence it is written in the last column. The user in my localhost is root and there was no password hence there is blank between inverted commas in third.
OUTPUT
The Output of the code is shown in screenshot below. It works perfectly fine.
I hope that we have solved your problem. For any further queries you can leave it on Comments.
Thank You!!!
How to Connect MySQL using PHP
Reviewed by Gaurav
on
11:15 AM
Rating:
Reviewed by Gaurav
on
11:15 AM
Rating:

No comments: