第一周学习知识点总结及感悟

2017-09-10  本文已影响0人  ve佐手

第一部分-知识点

1.git命令

2. 使用PDO连接数据库实现增删改查功能

function db(){
   try {
     $pdo = new PDO(mysql:host=" "; dbname=" ", username="root", passwd=" ");
     return $pdo;}catch ($e) {
     die("fail to connect mysql" .$e ->getMessage());
} 
}
function add($data) {
  $pdo = db();
  $sql = "INSERT INTO photo (name,path) VALUES(?,?)";
  $std = $pdo -> prepare($sql);
  $res = $std -> execute($data);
  return $res;
}  
function delete($id) {
  $pdo = db();
  $sql = "DELETE from photo where id = ?";
  $std = $pdo -> prepare($sql);
  $res = $std -> execute([$id]);
  return $res;
}
function update($data){
  $pdo = db();
  $sql = "UPDATE photo set name = ?,path = ? where id = ?";
  $std = $pdo -> prepare($sql);
  $res = $std ->execute($data);
  return $res;
}
function select() {
  $pdo = db();
  $sql = "select * from photo";
  $std = $pdo -> query($sql);
  $res = $std -> fetchALL();
  return $res;
}
function selectOne($id) {
  $pdo = db();
  $sql = "select * from photo where id = $id";
  $std = $pdo -> query($sql);
  $res = $std -> fetch();
  return $res;
} 
define('DB_ADDRESS','127.0.0.1');
define('DB_NAME','sys-photo');
define('DB_USER','root');
define('DB_PASS','123456');
上一篇下一篇

猜你喜欢

热点阅读