Difference between revisions of "Connecting to mysql"

From MyWiki
Jump to: navigation, search
Line 13: Line 13:
 
if (!$conn) {
 
if (!$conn) {
 
     die("Connection failed: " . mysqli_connect_error());
 
     die("Connection failed: " . mysqli_connect_error());
}
+
}  
echo  
+
echo "Connected successfully";
 +
?>
  
  

Revision as of 17:47, 10 November 2014

////Example (MySQLi Procedural)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
 
// Create connection
$conn = mysqli_connect($servername, $username, $password);
 
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
} 
echo "Connected successfully";
?> 
 
 
//closing the connection 
Example (MySQLi Procedural)
mysqli_close($conn);