本文整理匯總了PHP中DatabaseConnection::selectRowByID方法的典型用法代碼示例。如果您正苦於以下問題:PHP DatabaseConnection::selectRowByID方法的具體用法?PHP DatabaseConnection::selectRowByID怎麽用?PHP DatabaseConnection::selectRowByID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::selectRowByID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: find
/**
* Given an ID, finds a character with that ID
*
* @throws StatusCodeException 404 if it does not find the row
*
* @param DatabaseConnection database class instance
* @param mixed $id ID number, could be a string or an int
* @return array row of the database with that ID
*/
public static function find(DatabaseConnection $db, $id)
{
$array = $db->selectRowByID('SELECT * FROM characters WHERE id = ?', $id);
if ($array === NULL) {
throw new StatusCodeException(404);
}
return $array;
}
示例2: testQuery
public function testQuery()
{
require __DIR__ . '/config/database_test.php';
$db = new DatabaseConnection($host, $database, $user, $password);
$insert_result = $db->query("INSERT INTO characters (id, name, description, type, dead, stage, hp) \r\n\t\t\tVALUES ('9999', 'Carla', 'The swordmaster of Melee Island', 'pirate', 'false', '4', '87');");
$expected = ['id' => '9999', 'name' => 'Carla', 'description' => 'The swordmaster of Melee Island', 'type' => 'pirate', 'dead' => '0', 'stage' => '4', 'hp' => '87'];
$actual = $db->selectRowByID("SELECT * FROM characters WHERE id = '9999'");
$delete_result = $db->query("DELETE FROM characters WHERE id = '9999'");
$this->assertNotEmpty($actual, 'Character was not inserted properly, selectRowByID could not find it. Check TestDatabaseConnection::selectRowByID() and TestDatabaseConnection::query()');
$this->assertEquals($expected, $actual, 'Function query not returning expected value. Check TestDatabaseConnection::selectRowByID() and TestDatabaseConnection::query()');
$this->assertTrue($insert_result, 'Insert query failed. Check TestDatabaseConnection::query()');
$this->assertTrue($delete_result, 'Delete query failed. Check TestDatabaseConnection::query()');
}