Example #1
0
function retrieve_contact($shortname)
{
    require_once '../contacts/contacts_schema.inc.php';
    require_once '../contacts/db_config.inc.php';
    require_once 'SDO/DAS/Relational.php';
    $dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
    $das = new SDO_DAS_Relational($table_schema, 'contact', array($address_reference));
    $pdo_stmt = $dbh->prepare('select c.shortname, c.fullname, a.id, a.addressline1, a.addressline2, ' . ' a.city, a.state, a.zip, a.telephone from contact c, address a ' . 'where a.contact_id = c.shortname and c.shortname=?');
    return $das->executePreparedQuery($dbh, $pdo_stmt, array($shortname));
}
Example #2
0
$das = new SDO_DAS_Relational($database_metadata, 'company', $SDO_reference_metadata);
$dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
$root = $das->createRootDataObject();
$company = $root->createDataObject('company');
$company->name = "Acme";
$company->employee_of_the_month = null;
$das->applyChanges($dbh, $root);
echo "Created a company with name Acme and wrote it to the database\n";
/*************************************************************************************
 * Find it again (with its autogenerated id this time).
 *************************************************************************************/
$das = new SDO_DAS_Relational($database_metadata, 'company', $SDO_reference_metadata);
$dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
$name = 'Acme';
$pdo_stmt = $dbh->prepare('select name, id, employee_of_the_month from company where name=?');
$root = $das->executePreparedQuery($dbh, $pdo_stmt, array($name), array('company.name', 'company.id', 'company.employee_of_the_month'));
$company2 = $root['company'][0];
echo "Looked for Acme and found company with name = " . $company2->name . " and id " . $company2->id . "\n";
assert($company2->name == 'Acme');
assert($company2->employee_of_the_month === null);
/*************************************************************************************
 * Force a change in the databse behind the back of SDO
 *************************************************************************************/
$dbh2 = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
$count = $dbh2->exec("update company set name='ForcedNameChange' where name='Acme';");
echo "Update the company name behind the scenes\n";
echo "Number of rows updated = " . $count . "\n";
/*************************************************************************************
 * Update the SDO version of the record and and write it back again.
 * The collision detection test should fire here
 *************************************************************************************/
Example #3
0
 public function testPreparedExecuteQuery_ValueListMustBeNullOrAnArray()
 {
     $company_table = array('name' => 'company', 'columns' => array('id', 'name', 'employee_of_the_month'), 'PK' => 'id');
     $database_metadata = array($company_table);
     $exception_thrown = false;
     $das = new SDO_DAS_Relational($database_metadata);
     try {
         $company = $das->executePreparedQuery('dummy PDO handle', 'dummy PDO statement', 'a string, not an array or null');
     } catch (SDO_DAS_Relational_Exception $e) {
         $exception_thrown = true;
         $msg = $e->getMessage();
     }
     $this->assertTrue($exception_thrown, 'Exception was never thrown');
     $this->assertTrue(strpos($msg, 'third argument') != 0, 'Wrong message issued: ' . $msg);
     $this->assertTrue(strpos($msg, 'must be null or an array') != 0, 'Wrong message issued: ' . $msg);
 }
Example #4
0
$dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
$root = $das->createRootDataObject();
$employee = $root->createDataObject('employee');
$employee->name = "Sue";
$employee->SN = "001";
$das->applyChanges($dbh, $root);
echo "Created an employee with name Sue and wrote it to the database\n";
/*************************************************************************************
* Find it again (with its autogenerated id this time).
* Then update it and write it back again.
*************************************************************************************/
$das = new SDO_DAS_Relational($database_metadata);
$dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
$name = 'Sue';
$pdo_stmt = $dbh->prepare('select id, name, SN from employee where name=?');
$root = $das->executePreparedQuery($dbh, $pdo_stmt, array($name));
$sue = $root['employee'][0];
echo "Looked for Sue and found employee with name = " . $sue->name . " and SN " . $sue->SN . "\n";
$sue->name = 'Susan';
$sue->SN = 2;
$das->applyChanges($dbh, $root);
echo "Wrote back employee with name changed to Susan\n";
/*************************************************************************************
* Find it again under its new name, and delete it.
* Reuse the prepared query
*************************************************************************************/
$name = 'Susan';
$root = $das->executePreparedQuery($dbh, $pdo_stmt, array($name));
$susan = $root['employee'][0];
echo "Looked for Susan and found employee with name = " . $susan->name . " and SN " . $susan->SN . "\n";
unset($root['employee'][0]);