File name
Commit message
Commit date
File name
Commit message
Commit date
<?php
$user = "root";
$password = "1234";
$option = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
/* Try Catch */
try {
/* PDO Connection */
$db = new PDO("mysql:host=localhost;dbname=study", $user, $password, $option);
$db->exec("set names UTF8");
echo "<strong>Database Connection Success!!!</strong><br>";
} catch (PDOException $e) {
echo "<strong>Database Connection Fail!!!</strong>";
echo "<br>" . $e;
} finally {
}
/* Statement */
$stmt = $db->query("select * from address");
/* Query RUN, Result GET */
$result = $stmt->fetchAll();
foreach ($result as $value) {
echo "AGE : " . $value["age"] . "<br>";
}
$name = "안효원";
$age = 25;
$tel = "010-5635-5918";
$area = "강원도";
$birth = "1998-08-07";
/* Prepare Statement */
$stmt = $db -> prepare("insert into address values(NULL, ?, ?, ?, ?, ?)");
$stmt -> execute(array($name, $age, $tel, $area, $birth));