This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
kurs:doctrine_oracle_beipspiel [2012/01/19 11:19] mh |
kurs:doctrine_oracle_beipspiel [2014/09/10 21:22] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | <code> | + | ==== Entities definieren ===== |
+ | <code> | ||
<?php | <?php | ||
// entities/Test.php | // entities/Test.php | ||
Line 21: | Line 22: | ||
</code> | </code> | ||
- | XML | + | ==== XML ===== |
<code> | <code> | ||
Line 40: | Line 41: | ||
</code> | </code> | ||
- | <code> | + | ==== Konfiguration ==== |
+ | <code> | ||
<?php | <?php | ||
// bootstrap_doctrine.php | // bootstrap_doctrine.php | ||
Line 60: | Line 62: | ||
// database configuration parameters | // database configuration parameters | ||
$conn = array( | $conn = array( | ||
- | 'driver' => 'pdo_pgsql', | + | 'dbname' => 'orcl', |
- | 'host' => 'localhost', | + | 'user' => 'hr', |
- | 'port' => '5432', | + | 'password' => 'hr', |
- | 'dbname' => 'doctrine', | + | 'host' => '10.0.2.15', |
- | 'user' => 'dd', | + | 'port' => '1521', |
- | 'password' => 'dd', | + | 'driver' => 'oci8', |
+ | 'charset' => 'NLS_CHARACTERSET', | ||
); | ); | ||
- | |||
// obtaining the entity manager | // obtaining the entity manager | ||
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config); | $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config); | ||
+ | </code> | ||
+ | |||
+ | ==== Bootstrap Code ==== | ||
+ | |||
+ | <code> | ||
+ | <?php | ||
+ | // bootstrap.php | ||
+ | |||
+ | require_once "entities/Test.php"; | ||
+ | |||
+ | if (!class_exists("Doctrine\Common\Version", false)) { | ||
+ | require_once "bootstrap_doctrine.php"; | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | ==== cli-config ==== | ||
+ | |||
+ | <code> | ||
+ | |||
+ | <?php | ||
+ | // cli-config.php | ||
+ | require_once "bootstrap.php"; | ||
+ | |||
+ | $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array( | ||
+ | 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager) | ||
+ | )); | ||
+ | </code> | ||
+ | |||
+ | ==== Einfuegen ==== | ||
+ | <code> | ||
+ | |||
+ | <?php | ||
+ | // insert.php | ||
+ | require_once "bootstrap.php"; | ||
+ | |||
+ | $newTest = $argv[1]; | ||
+ | |||
+ | $test = new Test(); | ||
+ | $test->setName($newTest); | ||
+ | |||
+ | $entityManager->persist($test); | ||
+ | $entityManager->flush(); | ||
+ | |||
+ | echo "Created Test with ID " . $test->getId() . "\n"; | ||
+ | </code> | ||
+ | |||
+ | ==== Auslesen ==== | ||
+ | <code> | ||
+ | |||
+ | <?php | ||
+ | |||
+ | require_once "bootstrap.php"; | ||
+ | |||
+ | $dql = "SELECT t FROM Test t"; | ||
+ | |||
+ | $query = $entityManager->createQuery($dql); | ||
+ | $query->setMaxResults(30); | ||
+ | $tests = $query->getResult(); | ||
+ | |||
+ | foreach($tests AS $test) { | ||
+ | ## var_dump($test); | ||
+ | echo $test->getName()."\n"; | ||
+ | } | ||
</code> | </code> |