PHP databse Connectivity

PHP can work with many type of databases but most popular is MySQL . Lets do some practical and connect with database.
First of all start your wamp/xampp server and open phpmyadmin tool normally available with both,
For this open  http://localhost/phpmyadmin  in your browser.
Second  click on databases tab and create a database  with any name like testdb. 
Third open notepad and write below code in a new file and save in server root directory with php extension.
 Example : db.php

<?php
$servername='localhost';
$username='root';
$passwd='';
$dbname='testdb';
$conn=mysqli_connect($servername,$username,$passwd,$dbname);
if(!$conn)
{
 echo 'Could not connect:';
}else{
  echo 'Connection successfull';
}

?>


Forth step open http://localhost/db.php in your browser and you will see connection successful message in your browser.

No comments:

| Designed by Harhiktech