วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2558

PHP - Database(MySQL) Connect

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//Select database
$conn->select_db($dbname);

$conn->close();

echo "Connected successfully";

หรือ

$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$conn->close();

echo "Connected successfully";


ไม่มีความคิดเห็น:

แสดงความคิดเห็น