Database connection is important feature when you start developing a Dynamic website, on which you want user to register / login into your web application, so before allowing these user to login you need to store their information in your Database. And today am going to show you on how to make a database connection in your PHP project.
First of all you need to have a local server like XAMMP or WAMMP installed on your computer and make sure the server is turned on. This local server will allow your web application to communicate.
After turned on your XAMMP or WAMMP, open PHPMYADMIN or you can type on your browser localhost/phpmyadmin in the address bar. and the screen will open.
<?php | |
$db_name = "student"; | |
$username = "root"; | |
$password = ""; | |
$servename = "locaclhost"; | |
$conn = mysqli_connect($servename ,$username ,$password ,$db_name ); | |
if(!$conn){ | |
die("No connection to database"); | |
} else{ | |
echo "Successfully connected to database"; | |
} | |
?> |
1 Comments
There's some error in your code above, the severname is localhost I think it's typing error. Thanks for tutorials.
ReplyDelete