From af49359b8d967690c49ec982e423dea0984188ad Mon Sep 17 00:00:00 2001 From: Walt Sorensen Date: Sat, 3 Sep 2016 08:55:52 -0600 Subject: [PATCH] Add note about type casting Integer field values Integer field values should also be type cast to `(int)`. --- manual/en-US/coding-standards/chapters/php.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/manual/en-US/coding-standards/chapters/php.md b/manual/en-US/coding-standards/chapters/php.md index 0182128c..de7d11d5 100644 --- a/manual/en-US/coding-standards/chapters/php.md +++ b/manual/en-US/coding-standards/chapters/php.md @@ -476,7 +476,7 @@ To query our data source we can call a number of JDatabaseQuery methods; these m Use Query chaining to connect a number of query methods, one after the other, with each method returning an object that can support the next method, This improves readability and simplifies the resulting code. Since the Joomla Framework was introduced "query chaining" is now the recommended method for building database queries. Table names and table column names should always be enclosed in the `quoteName()` method to escape the table name and table columns. -Field values checked in a query should always be enclosed in the `quote()` method to escape the value before passing it to the database. +Field values checked in a query should always be enclosed in the `quote()` method to escape the value before passing it to the database. Integer field values checked in a query should also be type cast to `(int)`. ```php // Get the database connector. @@ -505,3 +505,15 @@ $query->select($db->quoteName(array('user_id', 'profile_key', 'profile_value', ' ->where($db->quoteName('profile_key') . ' LIKE '. $db->quote('\'custom.%\'')) ->order('ordering ASC'); ``` + +#### Chaining With Select Array And Type Casting Of Integer Field Value Example +```php +$query = $db->getQuery(true) + ->select(array( + $db->qn('profile_key'), + $db->qn('profile_value'), + )) + ->from($db->qn('#__user_profiles')) + ->where($db->qn('user_id') . ' = ' . $db->q((int) $userId)) + ->order($db->qn('ordering')); +```