/** * 创建数据表 * * @param MySQLPDO $pdo * @throws DbException */ public function createTb(MySQLPDO $pdo) { if ($this->isRuntimeInstallTable()) { $isCreate = $pdo->exec($this->installTableSQL()); if ($isCreate === false) { $error = json_encode($pdo->errorInfo()); throw new DbException('create table ' . $this->getTableName() . ' fail ' . $error); } } }
/** * @param Vo $vo * @return int 返回删除数据的行数 * @throws \Simple\Model\Exception\DbException * @throws \Simple\Exception\UnexpectedValueException */ public function delete(Vo $vo) { if (!$vo instanceof PDOVo) { throw new UnexpectedValueException('vo参数必须为PDOVo对象。'); } $priKey = $vo->getPrimaryKey(); $where = " `{$priKey}`=:{$priKey} "; $tbName = $vo->getTableName(); $sql = "DELETE FROM `" . $tbName . "` WHERE " . $where; Debug::trace('delete:' . $sql, 'mysql'); $sth = $this->_link->prepare($sql); $sth->bindValue(":{$priKey}", call_user_func_array(array(&$vo, "get" . ucfirst($priKey)), array())); $ret = $sth->execute(); if ($ret === false) { throw new DbException($sth->errorInfo(), $sth->errorCode()); } return $sth->rowCount(); }