Commit 5b0e755b authored by 吴多智's avatar 吴多智

Upload new file

parent b5ea2148
<?php
$settings = include "config.php";
class MyDB{
protected static $setting = array(
'dsn'=>'mysql:dbname=lab;host=localhost;port=3306',
'username'=>'root',
'password'=>''
);
protected static $_instance;
private static $pdo;
private function __construct(){}
public static function getDB(){
if(!isset(self::$_instance)){
try{
self::$pdo = new PDO(self::$setting['dsn'],self::$setting['username'],self::$setting['password']);
}catch(PDOException $e){
die('Could not connect to the database:<br/>' . $e);
}
$c=__CLASS__;
self::$_instance = new $c;
}
return self::$_instance;
}
public function query($sql,$array=array()){
$stmt = self::$pdo->prepare($sql);
$stmt->execute($array);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}
}
$sql = "select * from book where id > :id";
$array = array("id"=>1);
$db = MyDB::getDB();
$result = $db->query($sql,$array);
var_dump($result);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment