本文整理汇总了PHP中Dao::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Dao::create方法的具体用法?PHP Dao::create怎么用?PHP Dao::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dao
的用法示例。
在下文中一共展示了Dao::create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDao
public function createDao($tableName)
{
if (!$this->pdoReady()) {
throw new PeeweeException("接続が初期化されていません");
}
if (empty($tableName)) {
throw new PeeweeException("テーブル名が指定されていません。");
}
$dao = Dao::create($this->pdo, $tableName);
return $dao;
}
示例2: create
public function create(Vo $vo)
{
$vo->setSenha(md5($vo->getSenha()));
return parent::create($vo);
}
示例3: search
public function search($conditions = array(), $page = array(), $relations = array())
{
if (!$this->pdoReady()) {
throw new Exception("接続が初期化されていません");
}
if (empty($this->tableName)) {
throw new Exception("テーブル名を指定してください");
}
if ($conditions == null) {
$conditions = array();
}
if ($page == null) {
$page = array();
}
if ($relations == null) {
$relations = array();
}
$sql = "select * from " . $this->tableName;
if (!empty($conditions)) {
$sql .= " where ";
$index = 0;
foreach ($conditions as $key => $value) {
if ($index != 0) {
$sql .= " and ";
}
$sql .= $key . "= :{$key} ";
$index++;
}
}
$pageNumber = $page["page"];
$pageCount = $page["count"];
if (empty($pageNumber) || empty($pageCount)) {
} else {
$offset = ($pageNumber - 1) * $pageCount;
$sql .= " limit " . $offset . " , " . $pageCount;
}
$stmt = $this->pdo->prepare($sql);
foreach ($conditions as $key => $value) {
$stmt->bindValue(":" . $key, $value);
}
$result = $stmt->execute();
$resultArray = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$Dto = new Dto($this->tableName);
foreach ($row as $columnKey => $columnValue) {
$Dto->{$columnKey} = $this->convertTypeMismatch($columnKey, $columnValue);
}
$resultArray[] = $Dto;
}
if (!empty($relations)) {
for ($i = 0; $i < count($resultArray); $i++) {
$result = $resultArray[$i];
foreach ($relations as $relationTableName => $relationKeys) {
$relationParams = array();
foreach ($relationKeys as $relationKey => $foreignKey) {
$relationParams[$foreignKey] = $result->{$relationKey};
}
$relationDao = Dao::create($this->pdo, $relationTableName);
$relationList = $relationDao->search($relationParams);
$result->{$relationTableName} = $relationList;
}
$resultArray[$i] = $result;
}
}
return $resultArray;
}