Chapter 9: DQL (Doctrine Query Language) 128 Listing 9-33 // test.php // ... $q = Doctrine_Query::create() ->update('Account') ->set('amount', 'amount + 200') ->where('id > 200'); // If you just want to set the amount to a value $q->set('amount', '?', 500); echo $q->getSqlQuery(); The above call to getSql() would output the following SQL query: Listing 9-34 UPDATE account SET amount = amount + 200 WHERE id > 200 Now to perform the update is simple. Just execute the query: Listing 9-35 // test.php // ... $rows = $q->execute(); echo $rows; DELETE Queries Listing 9-36 DELETE FROM WHERE ORDER BY LIMIT • The DELETE statement deletes records from component_name and returns the number of records deleted. • The optional WHERE clause specifies the conditions that identify which records to delete. Without WHERE clause, all records are deleted. • If the ORDER BY clause is specified, the records are deleted in the order that is specified. • The LIMIT clause places a limit on the number of rows that can be deleted. The statement will stop as soon as it has deleted record_count records. Listing 9-37 // test.php // ... $q = Doctrine_Query::create() ->delete('Account a') ->where('a.id > 3'); echo $q->getSqlQuery(); The above call to getSql() would output the following SQL query: ----------------- Brought to you by
Chapter 9: DQL (Doctrine Query Language) 129 DELETE FROM account WHERE id > 3 Listing 9-38 Now executing the DELETE query is just as you would think: // test.php Listing 9-39 // ... $rows = $q->execute(); echo $rows; When executing DQL UPDATE and DELETE queries the executing of a query returns the number of affected rows. FROM clause Syntax: FROM [[LEFT | INNER] JOIN ] ... Listing 9-40 The FROM clause indicates the component or components from which to retrieve records. If you name more than one component, you are performing a join. For each table specified, you can optionally specify an alias. Consider the following DQL query: // test.php Listing 9-41 // ... $q = Doctrine_Query::create() ->select('u.id') ->from('User u'); echo $q->getSqlQuery(); The above call to getSql() would output the following SQL query: SELECT u.id AS u__id FROM user u Listing 9-42 Here User is the name of the class (component) and u is the alias. You should always use short aliases, since most of the time those make the query much shorther and also because when using for example caching the cached form of the query takes less space when short aliases are being used. JOIN syntax DQL JOIN Syntax: ----------------- Brought to you by
The comprehensive data will ensure that marketers can save on their marketing costs by using a single database for all their marketing purposes. With our Mailing Lists of Medical Associates you can expand your business, gain new customers, networking with associate medical directors, reduce sales cycle and improve sales, revenue and ROI.
Test4Direct provides latest PDF questions of IBM C2090-610 exam. You have an opportunity to pass the IBM C2090-610 exam in one go. Test4Direct is most accurate source to prepare IBM C2090-610 exam as your success will become site’s responsibility after purchasing C2090-610 exam product. There are also lots of discounts and promotion offers that you can avail. Let’s try a free demo http://www.test4direct.com/C2090-610.html