분류 php

Mysqli + PHP 데이터베이스에 연결하는 방법

컨텐츠 정보

  • 조회 396 (작성일 )

본문

$mysqli = new mysqli("localhost", "username", "password", "databasename");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "\n";

$mysqli = new mysqli("127.0.0.1", "username", "password", "databasename", 3306);
if ($mysqli->connect_errno) {
   echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

echo $mysqli->host_info . "\n";
php