當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DatabaseObject::load方法代碼示例

本文整理匯總了PHP中DatabaseObject::load方法的典型用法代碼示例。如果您正苦於以下問題:PHP DatabaseObject::load方法的具體用法?PHP DatabaseObject::load怎麽用?PHP DatabaseObject::load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DatabaseObject的用法示例。


在下文中一共展示了DatabaseObject::load方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testDummy

 public function testDummy()
 {
     // Test meta object
     $meta = DatabaseObjectMeta::forClass('DBODummy');
     $table = $meta->getTable();
     $key = $meta->getKey();
     $this->assertEqual('DBODummy', $meta->getClass());
     $this->assertEqual('dbodummy', $table);
     $this->assertEqual('dbodummy_id', $key);
     $colMap = $meta->getColumnMap();
     $this->assertEqual($colMap["aDate"], "a_date");
     $this->assertEqual($colMap["aDateTime"], "a_date_time");
     $this->assertEqual($colMap["aTime"], "a_time");
     $this->assertEqual($colMap["mess"], "mess");
     $this->assertEqual($colMap["id"], "dbodummy_id");
     $fieldSet = $meta->getFieldSetSQL();
     $this->assertEqual($fieldSet, implode(', ', array('`a_date`=FROM_UNIXTIME(:a_date)', '`a_date_time`=FROM_UNIXTIME(:a_date_time)', '`a_time`=SEC_TO_TIME(:a_time)', '`mess`=:mess')));
     $pfx = "`{$table}`.";
     $colSQL = $meta->getColumnsSQL();
     $this->assertEqual($colSQL, implode(', ', array("UNIX_TIMESTAMP({$pfx}`a_date`) AS `a_date`", "UNIX_TIMESTAMP({$pfx}`a_date_time`) AS `a_date_time`", "TIME_TO_SEC({$pfx}`a_time`) AS `a_time`", "{$pfx}`mess` AS `mess`")));
     $colSQL = $meta->getColumnsSQL(null, null);
     $this->assertEqual($colSQL, implode(', ', array("UNIX_TIMESTAMP(`a_date`) AS `a_date`", "UNIX_TIMESTAMP(`a_date_time`) AS `a_date_time`", "TIME_TO_SEC(`a_time`) AS `a_time`", "`mess` AS `mess`")));
     $drop = "DROP TABLE IF EXISTS {$table}";
     $create = "CREATE TABLE {$table} (\n  " . implode(",\n  ", DBODummy::$CreateSpec) . "\n)";
     $this->expectExact('perform', $drop);
     $this->expectExact('perform', $create);
     $this->db->perform($drop);
     $this->db->perform($create);
     $dummy = new DBODummy();
     // Create a dummy
     $this->populate($dummy);
     // TODO populate really should be a method on the object or its meta
     $this->expectExact('lock', "LOCK TABLES {$table} WRITE");
     $this->expectExact('prepare', "INSERT INTO `{$table}` SET {$fieldSet}");
     $this->expectExact('execute', json_encode(array(":a_date" => (int) $dummy->aDate, ":a_date_time" => (int) $dummy->aDateTime, ":a_time" => (int) $dummy->aTime, ":mess" => $dummy->mess)));
     $this->expectExact('lastInsertId', 1);
     // The table is virgin
     $this->expectExact('unlock', 'UNLOCK TABLES');
     $dummy->create();
     // Change the dummy and save
     $this->populate($dummy);
     $this->expectExact('prepare', "UPDATE `{$table}` SET {$fieldSet} WHERE `{$key}` = :{$key} LIMIT 1");
     $this->expectExact('execute', json_encode(array(":a_date" => (int) $dummy->aDate, ":a_date_time" => (int) $dummy->aDateTime, ":a_time" => (int) $dummy->aTime, ":mess" => $dummy->mess, ":dbodummy_id" => $dummy->id)));
     $dummy->update();
     // Fetch a dummy
     $dummyId = $dummy->id;
     $dummyData = array($dummy->aDate, $dummy->aDateTime, $dummy->aTime, $dummy->mess);
     $dummy = null;
     $this->expectExact('prepare', "SELECT {$colSQL} FROM `{$table}` WHERE `{$key}` = ? LIMIT 1");
     $this->expectExact('executef', json_encode(array($dummyId)));
     $dummy = DatabaseObject::load('DBODummy', $dummyId);
     $this->assertEqual($dummyId, $dummy->id);
     $this->assertEqual($dummyData[0], $dummy->aDate);
     $this->assertEqual($dummyData[1], $dummy->aDateTime);
     $this->assertEqual($dummyData[2], $dummy->aTime);
     $this->assertEqual($dummyData[3], $dummy->mess);
     // Kill a dummy
     $this->expectExact('prepare', "DELETE FROM `{$table}` WHERE `{$key}` = ?");
     $this->expectExact('executef', json_encode(array($dummyId)));
     $dummy->delete();
     $this->assertEqual(-1, $dummy->id);
     // Delete only clears id
     $this->assertEqual($dummyData[0], $dummy->aDate);
     $this->assertEqual($dummyData[1], $dummy->aDateTime);
     $this->assertEqual($dummyData[2], $dummy->aTime);
     $this->assertEqual($dummyData[3], $dummy->mess);
     // TODO once wipe added, values should be nullifed
     // TODO update a non-existent id should fail
     // TODO fetch non-existent id should fail
 }
開發者ID:bprudent,項目名稱:framework,代碼行數:70,代碼來源:DatabaseObjectTest.php

示例2: loadFor

 public static function loadFor($linkClass, DatabaseObject $for)
 {
     assert(class_exists($linkClass));
     assert(is_subclass_of($linkClass, __CLASS__));
     if (!isset($for->id)) {
         throw new InvalidArgumentException('unsaved DatabaseObject');
     }
     $database = $for->getDatabase();
     $meta = DatabaseObjectLinkMeta::forClass($linkClass, $for->_db);
     $data = array();
     if (is_a($for, $meta->getFromClass())) {
         $sql = $meta->getSQL('link_load_from');
         $data['from'] = $for;
         $other = 'to';
         $otherClass = $meta->getToClass();
     } elseif (is_a($for, $meta->getToClass())) {
         $sql = $meta->getSQL('link_load_to');
         $data['to'] = $for;
         $other = 'from';
         $otherClass = $meta->getFromClass();
     } else {
         throw new InvalidArgumentException('invalid DatabaseObject, expecting a ' . $meta->getFromClass() . 'or a ' . $meta->getToClass());
     }
     $otherId = null;
     $list = $database->execute($sql, $for->id);
     $list->bindColumn(1, $otherId);
     $i = 1;
     foreach (array_merge($meta->getAdditionalKey(), $meta->getAutomaticColumns()) as $column) {
         $data[$column] = null;
         $list->bindColumn(++$i, $data[$column]);
     }
     $r = array();
     $call = array($linkClass, 'factory');
     while ($list->fetch()) {
         $data[$other] = DatabaseObject::load($otherClass, $otherId);
         array_push($r, call_user_func($call, $data));
     }
     return $r;
 }
開發者ID:jcorbinredtree,項目名稱:framework,代碼行數:39,代碼來源:DatabaseObjectLink.php

示例3: load

 public static function load($id)
 {
     return DatabaseObject::load(__CLASS__, $id);
 }
開發者ID:jcorbinredtree,項目名稱:cms,代碼行數:4,代碼來源:CMSNode.php


注:本文中的DatabaseObject::load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。