PT.BUZOO INDONESIA is No1 Japanese offshore development company in Indonesia.
We are professional of web solution and smartphone apps. We can support Japanese, English and Indonesia.
We are hiring now at http://buzoo.co.id/
3. Zend_Db_Adapter
Zend_Db_Adapter is the basic class you use
to connect your PHP application to
an RDBMS. There is a different Adapter class
for each brand of RDBMS.
10. Reading Query Results
1.
2.
3.
4.
5.
6.
Fetching a Complete Result Set
Fetching a Single Row from a Result Set
Fetching a Single Scalar from a Result Set
Fetching a Result Set as an Associative
Array
Fetching Key-Value Pairs from a Result
Set
Fetching a Single Column from a Result
Set
12. 2. Fetching a Single Row from
a Result Set
$models = $this->db()->fetchRow(
“SELECT * FROM `dtb_customer` LIMIT 1”
);
print_r($models);
echo $models[`customerID`]; //44
Array (
[customerID]
[customerName]
[customerAddr]
[customerPhone]
[create_date]
[update_date]
)
=>
=>
=>
=>
=>
=>
44
Adisti Prihartini
Maleo 345 Bintan
2390554
2012-11-05 10:09:14
2012-11-21 10:35:45
13. 3. Fetching a Single Scalar
from a Result Set
$models = $this->db()->fetchOne(
“SELECT `customerID` FROM `dtb_customer` LIMIT 1”
);
print_r($models);
echo $models[`customerID`];
44
14. Modifying Data to the
Database
1.
2.
3.
Inserting Data
Updating Data
Deleting Data
18. Preventing SQL Injection
$name = "O'Reilly";
$sql =
"SELECT * FROM `dtb_customer` WHERE
`customerName` = '$name'";
echo $sql;
// SELECT * FROM `dtb_customer` WHERE `customerName`
= 'O'Reilly'
19. Quoting Values and Identifiers
1.
2.
3.
Using quote()
Using quoteInto()
Using quoteIdentifier()
20. 1. Using quote()
$name = $this->db()->quote("O'Reilly");
$sql =
"SELECT * FROM `dtb_customer` WHERE `customerName` =
$name";
echo $sql;
// SELECT * FROM `dtb_customer` WHERE `customerName` = 'O'Reilly'
$phone = $this->db()->quote("1234", "INTEGER");
$sql =
"SELECT * FROM `dtb_customer` WHERE
`customerPhone` = $phone";
echo $sql;
// SELECT * FROM `dtb_customer` WHERE `customerPhone` = 1234
21. 2. Using quoteInto()
$name = "O'Reilly";
$sql = $this->db()->quoteInto(
"SELECT * FROM `dtb_customer`
WHERE `customerName` = ?", $name
);
echo $sql;
// SELECT * FROM `dtb_customer` WHERE `customerName` = 'O'Reilly'
22. Notes
Always
store your logic query in
Models/Logic/your_logic.php
Minimizing the possibility of SQL injection
with quoting values
When creating logic, please reduce the
possibility of errors
Always return your logic result value
Always check the existing logic before
you make yours