개발자의 끄적끄적

[php] mysqli 를 이용한 접속 예제 소스 본문

개발/php

[php] mysqli 를 이용한 접속 예제 소스

효벨 2020. 10. 2. 02:00
728x90
반응형

[php] mysqli 를 이용한 접속 예제 소스

 

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn= mysqli_connect($servername,$username,$password,$dbname);
// Check connection
if (!$conn) {
  die("Connection failed: " . mysqli_connect_error());
}
echo "Connected Successfully.";
?>

 

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

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

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


Simplified

$conn = mysqli_connect('localhost', 'username', 'password');
$database = mysqli_select_db($conn, 'database');

 

출처 : www.codegrepper.com/code-examples/php/connect+to+mysql+in+php+7

반응형
Comments