Berikut Ini Contoh Script PHP Connect to MySQL
Contoh 1:
<?php
$conn = mysql_connect('192.168.1.40', 'User', 'Password');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
$conn = mysql_connect('192.168.1.40', 'User', 'Password');
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
Contoh 2 :
<?php
// Create connection
$con=mysqli_connect("192.168.1.40","User","Password","Database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo "Connected successfully";
}
?>
// Create connection
$con=mysqli_connect("192.168.1.40","User","Password","Database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
else {
echo "Connected successfully";
}
?>