v5:reference:connection:param
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
reference:param [2015/08/21 20:58] – created mnewnham | v5:reference:connection:param [2020/01/25 00:31] – [Usage] split long line dregad | ||
---|---|---|---|
Line 2: | Line 2: | ||
~~NOTOC~~ | ~~NOTOC~~ | ||
<WRAP right box> | <WRAP right box> | ||
+ | ==See Also== | ||
+ | [[v5: | ||
== Syntax == | == Syntax == | ||
string param( | string param( | ||
- | | + | |
- | | + | |
) | ) | ||
</ | </ | ||
===== Description ===== | ===== Description ===== | ||
The function param returns a database-specific placeholder for a prepared query statement. | The function param returns a database-specific placeholder for a prepared query statement. | ||
+ | |||
+ | 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 | + | . ' AND total = ' . $db-> |
- | */ | + | $db-> |
- | print $db-> | + | $sql2 = ' |
- | /* | + | |
- | * prints | + | |
- | */ | + | |
</ | </ | ||
- | <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