v5:reference:connection:param
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
v5:reference:connection:param [2017/05/17 19:18] – mnewnham | v5:reference:connection:param [2020/01/25 00:33] – [Usage] dregad | ||
---|---|---|---|
Line 2: | Line 2: | ||
~~NOTOC~~ | ~~NOTOC~~ | ||
<WRAP right box> | <WRAP right box> | ||
+ | ==See Also== | ||
+ | [[v5: | ||
== Syntax == | == Syntax == | ||
string param( | string param( | ||
Line 11: | Line 13: | ||
This method is used with [[v5: | This method is used with [[v5: | ||
+ | |||
+ | On RDBMS with positional (numbered) query parameters such as PostgreSQL, calling '' | ||
+ | |||
------------------------------ | ------------------------------ | ||
===== Usage ===== | ===== Usage ===== | ||
+ | |||
+ | This is an example of how to use param() to build SQL queries: | ||
+ | |||
<code php> | <code php> | ||
- | /* | + | $sql1 = ' |
- | * Connection to Oracle database | + | . 'name = ' |
- | */ | + | . 'total = ' . $db-> |
- | print $db-> | + | |
- | /* | + | $db-> |
- | * prints | + | $sql2 = ' |
- | */ | + | |
</ | </ | ||
- | <code php> | + | |
- | /* | + | See below for the code's output with various database drivers. |
- | * Connection to IBM DB2 database | + | |
- | */ | + | ==== MySQL, |
- | print $db->param(' | + | < |
- | /* | + | $sql1: SELECT |
- | * prints ? | + | $sql2: SELECT * FROM accounts WHERE id = ? |
- | */ | + | </code> |
+ | |||
+ | ==== Oracle | ||
+ | < | ||
+ | $sql1: SELECT | ||
+ | $sql2: SELECT | ||
+ | </code> | ||
+ | |||
+ | ==== PostgreSQL ==== | ||
+ | < | ||
+ | $sql1: SELECT * FROM accounts WHERE name = $1 AND total = $2 | ||
+ | $sql2: SELECT * FROM accounts WHERE id = $1 | ||
</ | </ | ||
v5/reference/connection/param.txt · Last modified: 2021/02/26 01:35 by dregad