File name
Commit message
Commit date
File name
Commit message
Commit date
<?php
class DB
{
private $user = "root";
private $password = "1234";
private $option = array(PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION);
private $db;
public function __construct(){
try {
$this->db = new PDO("mysql:host=localhost;dbname=study", $this->user, $this->password, $this->option);
$this->db->exec("set names UTF8");
}catch (PDOException $e){
echo "<h2>Database Connection FAIL!!</h2>";
echo "Because : " . $e . "<hr>";
}
}
public function getDB() {
return $this->db;
}
public function selectTest() {
try {
$stmt = $this->db->prepare("select * from address where name = ? limit 1");
$stmt->execute(array("안효원"));
$result = $stmt->fetchAll();
return $result;
} catch (PDOException $e){
return $e;
}
}
public function insertTest($name, $age, $tel, $area, $birth) {
try {
$stmt = $this->db->prepare("insert into address values(NULL, ?, ?, ?, ?, ?)");
$stmt->execute(array($name, $age, $tel, $area, $birth));
return true;
}catch (PDOException $e) {
echo $e;
return false;
}
}
public function updateTest($name) {
try {
$stmt = $this->db->prepare("update address set name=? where name='안효원'");
$stmt->execute(array($name));
return true;
}catch (PDOException $e) {
echo $e;
return false;
}
}
public function deleteTest($name) {
try {
$stmt = $this->db->prepare("delete from address where name=?");
$stmt->execute(array($name));
return true;
}catch (PDOException $e){
echo $e;
return false;
}
}
}