PHP utility collection with hybrid and fluent APIs.

βŒˆβŒ‹ βŽ‡ branch:  hybrid7 libraries


Check-in [f9ecfa3ce9]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:ASCII documentation box for db() placeholder syntax and uses.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f9ecfa3ce95a8af09c66249bc5e3059da4af0be6
User & Date: mario 2014-08-14 07:41:07
Context
2014-08-14
07:43
Relaxed _http() filter to allow leading numerics in host name, Added missing `p` tag in _strip_markup(). check-in: d467a4be29 user: mario tags: trunk
07:41
ASCII documentation box for db() placeholder syntax and uses. check-in: f9ecfa3ce9 user: mario tags: trunk
07:39
Added static $defaults[] array instead of built-in constructor calls. Introduces ->assert() to test CURL/HTTP properties after ->exec(), and possibly drop the result on mismatches. check-in: 49b2714f5f user: mario tags: trunk
Changes

Changes to db.php.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34














35
36
37
38
39
40
41
 *
 * Provides simple database queries with enumerated / named parameters. It's
 * flexible in accepting plain PDO scalar arguments or arrays. Array args get
 * merged, or transcribed when special placeholders are present:
 *
 *   $r = db("SELECT * FROM tbl WHERE a>=? AND b IN (??)", $a, array($b, $c));
 *
 * Extended placeholder syntax:
 *
 *      ??    Interpolation of indexed arrays - useful for IN clauses.
 *      ::    Turns associative arrays into a :named, :value, :list.
 *      :?    Interpolates key names (ignores values).
 *
 *      :&    Becomes a `name`=:value list, joined by AND - for WHERE clauses.
 *      :|    Becomes a `name`=:value list, joined by OR - for WHERE clauses.
 *      :,    Becomes a `name`=:value list, joined by , commas - for UPDATEs.
 *
 *      :*    Expression placeholder, where the associated argument should
 *            contain an array ["AND foo IN (??)", $params] - which only
 *            interpolates if $params contains any value.  Can be nested.














 *
 * Configurable {TOKENS} from db()->tokens[] are also substituted..
 *
 *
 * RESULT
 *
 * The returned result can be accessed as single data row, when fetching just







|

|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 *
 * Provides simple database queries with enumerated / named parameters. It's
 * flexible in accepting plain PDO scalar arguments or arrays. Array args get
 * merged, or transcribed when special placeholders are present:
 *
 *   $r = db("SELECT * FROM tbl WHERE a>=? AND b IN (??)", $a, array($b, $c));
 *
 * Extended placeholder syntax and common uses:
 *
 *  β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
 *  β”‚PlcH β”‚  Expands to  β”‚ Context β”‚                Purpose                 β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ ??  β”‚ ?, ?, ?      β”‚ IN      β”‚ Expansion of indexed arrays.           β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ ::  β”‚ :a, :b       β”‚ VALUES  β”‚ Expand  associative  arrays into named β”‚
 *  β”‚     β”‚              β”‚         β”‚ value list.                            β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ :?  β”‚ β€˜aβ€˜, β€˜bβ€˜     β”‚ Names   β”‚ Interpolates key names (does  not  pa‐ β”‚
 *  β”‚     β”‚              β”‚         β”‚ rameterize values).                    β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ :&  β”‚ x=:x         β”‚ WHERE   β”‚ Becomes AND‐joined name=:value list.   β”‚
 *  β”‚     β”‚  AND y=:y    β”‚         β”‚                                        β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ :|  β”‚ x=:x         β”‚ WHERE   β”‚ Becomes OR‐joined name=:value list.    β”‚
 *  β”‚     β”‚  OR y=:y     β”‚         β”‚                                        β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ :,  β”‚ x=:x, y=:y   β”‚ UPDATE  β”‚ Becomes comma‐joined name=:value list. β”‚
 *  β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
 *  β”‚ :*  β”‚ SQL + params β”‚ Expr    β”‚ Expression  placeholder, where the as‐ β”‚
 *  β”‚     β”‚              β”‚         β”‚ sociated argument  should  contain  an β”‚
 *  β”‚     β”‚              β”‚         β”‚ array  ["AND  foo  IN (??)", $params]. β”‚
 *  β”‚     β”‚              β”‚         β”‚ Which  only  interpolates  if  $params β”‚
 *  β”‚     β”‚              β”‚         β”‚ contains any value. Can be nested.     β”‚
 *  β””β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
 *
 * Configurable {TOKENS} from db()->tokens[] are also substituted..
 *
 *
 * RESULT
 *
 * The returned result can be accessed as single data row, when fetching just