Friday, August 16, 2019

How to connect to mysqli in PHP

Today i will introduce for you a how to connect database mysql in php, this is problem very meet in code php.
How to connect to mysqli in PHP

Write function connect to mysql in php below:
   <?php
 
    $server ='localhost';
$user ='root';
$pass ='';
    $conn = mysqli_connect($server,$user,$pass);
if(!$conn){
die("don't connect :" .mysql_error());
}
echo "Connected successfully";
mysqli_close($conn);
   ?>
use php in HTML
<html>
   <head>
      <title>How to connect to mysql</title>
   </head>
   <body>
 
   <?php
 
    $server ='localhost';
$user ='root';
$pass ='';
    $conn = mysqli_connect($server,$user,$pass);
if(!$conn){
die("don't connect :" .mysql_error());
}
echo "Connected successfully";
mysqli_close($conn);
   ?>
   
   </body>
 
</html>

No comments:

Post a Comment