* to keep this example shorter, no try/catch blocks * to make it quite clear that we work disconnected, get a fresh DAS and PDO handle each time *************************************************************************************/ /************************************************************************************* * Empty out the company table *************************************************************************************/ $dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD); $count = $dbh->exec('DELETE FROM company;'); echo "Emptied out the company table with DELETE FROM company\n"; /************************************************************************************* * Create the root data object then a single company object underneath it. * Set the company name to 'Acme'. *************************************************************************************/ $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";