Exemplo n.º 1
0
 /**
  * Update author with new data
  *
  * @param  $id arrray $attributes
  * @return null
  */
 public function doUpdate($id, array $attributes = [], array $options = [])
 {
     $validator = $this->getValidator($attributes);
     if (!$validator->validate()) {
         $messages = [];
         foreach ($validator->errors() as $fieldName => $errors) {
             $messages[] = current($errors);
         }
         $message = implode("\n", $messages);
         throw new \Exception($message);
     }
     $one = PdoLite::filterBySchema("authors", $attributes);
     return self::update("authors", ['fl' => $one, 'where' => "id=" . $id]);
 }
Exemplo n.º 2
0
$db->pln($db->select("authors", ['where' => "id={$lastid}"]), "RS of last insert: {$lastid}");
$db->pln($db->delete("authors", ['where' => "id={$lastid}"]), "deleted {$lastid}");
$db->pln($db->select("authors"), "select-aft");
echo "<br />rows2array-after";
// various select test case
$db->pln($db->select("authors", ['fl' => 'name', 'type' => 'both', 'where' => 'id=1']), "both-name", 'p');
$db->pln($db->select("authors", ['fl' => 'id, name,xid', 'where' => 'id=1']), "name,xid");
$db->pln($db->select("authors", ['fl' => $iArray, 'type' => 'num', 'where' => 'id=1']), "num");
$db->pln($db->select("books", ['where' => 'id<3']), "assoc");
$db->pln($db->select("books", ['where' => 'id<3', 'all' => 'all']), "all-assoc");
$db->pln($db->dbRow("authors", ['where' => 'id=1']), 'dbRow');
$db->pln($db->dbField("authors", "name", 'id=1'), 'dbFieldValue');
// schema test case
$fields = $db->fieldsKey("authors", "_none");
$db->pln($fields, "schema", 'p');
$one = $db->filterBySchema("authors", $iArray);
$db->pln($one, "schema filter");
$db->pln($db->getNextId("books", "id"), "next books id");
// array to string
$db->pln($db->a2sSelect($one), "select");
$db->pln($db->a2sInsert($one), "insert");
$db->pln($db->a2sUpdate($one), "update");
$db->pln($db->a2sSelect($iArray), "select");
// old test case
$sql = $db->qbSelect("books", ['where' => "id <3"]);
$db->pln($sql, "sql");
echo "<p />Samples use object _call dbFetch";
$db->pln($db->row2Array($sql), "row2array-num");
$db->pln($db->row2Array($sql, "assoc"), "row2array-assoc");
$db->pln($db->dbFetchAssoc($db->query($sql)), "dbFetchAssoc");
echo "<br />Samples use static __callStatic dbFetch: ";