本文整理汇总了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()');
}