10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9: DQL (<strong>Doctrine</strong> Query Language) 123<br />

$account = new Account();<br />

$account->name = 'test 1';<br />

$account->amount = '100.00';<br />

$account->save();<br />

$account = new Account();<br />

$account->name = 'test 2';<br />

$account->amount = '200.00';<br />

$account->save();<br />

Be sure to execute test.php:<br />

$ php test.php<br />

Listing<br />

9-9<br />

Now you can test the selecting of the data with these next few sample queries:<br />

// test.php<br />

Listing<br />

9-10<br />

// ...<br />

$q = <strong>Doctrine</strong>_Query::create()<br />

->select('a.name')<br />

->from('Account a');<br />

echo $q->getSqlQuery();<br />

Lets take a look at the SQL that would be g<strong>en</strong>erated by the above query:<br />

SELECT<br />

a.id AS a__id,<br />

a.name AS a__name<br />

FROM account a<br />

Listing<br />

9-11<br />

// test.php<br />

Listing<br />

9-12<br />

// ...<br />

$accounts = $q->execute();<br />

print_r($accounts->toArray());<br />

The above example would produce the following output:<br />

$ php test.php<br />

Array<br />

(<br />

[0] => Array<br />

(<br />

[id] => 1<br />

[name] => test 1<br />

[amount] =><br />

)<br />

Listing<br />

9-13<br />

[1] => Array<br />

(<br />

[id] => 2<br />

[name] => test 2<br />

[amount] =><br />

)<br />

)<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!