Parameters
$sql - The SQL statement.
Returns
An array of record columns.
Syntax
| PHP |
|
public function Retrieve(string $sql) : ?array
|
Retrieves a record for the provided SQL statement.
Example
| PHP |
// Retrieves a record for the provided SQL statement.
private static function Retrieve(LJCConnectionValues $connectionValues)
{
// See constructor for how to create $connectionValues.
$dbAccess = new LJCDbAccess($connectionValues);
$tableName = "TableName";
// Insert test record.
$name = "Test";
$sql = "insert into {$tableName}\r\n ";
$sql .= "(Name)\r\n ";
$sql .= "values('{$name}');";
$affectedCount = $dbAccess->Execute($sql);
if (0 == $affectedCount)
{
echo("\r\nRetrieve() No record inserted.");
}
// Retrieve assigned ID.
$sql = "select\r\n ";
$sql .= "ID, Name\r\n ";
$sql .= "from {$tableName}\r\n ";
$sql .= "where Name = '{$name}';";
$row = $dbAccess->Retrieve($sql);
if ($row == null)
{
echo("\r\nRetrieve() select row not found");
}
$id = LJCDbAccess::GetValue($row, "ID");
if ($id == null)
{
echo("\r\nRetrieve() ID not found");
}
// Delete test record.
if ($id != null)
{
$sql = "delete from {$tableName}\r\n ";
$sql .= "where ID = {$id};";
$affectedCount = $dbAccess->Execute($sql);
if (0 == $affectedCount)
{
echo("\r\nRetrieve() No record found to delete.");
}
}
}
|
Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.