ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:param

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
v5:reference:connection:param [2017/05/17 19:18] mnewnhamv5: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:reference:connection:addq|addQ()]]\\
 == Syntax == == Syntax ==
   string param(   string param(
Line 11: Line 13:
  
 This method is used with [[v5:userguide:learn_bind:bind_vars|bind variable SQL statement execution]], to produce injection resistant code. This method is used with [[v5:userguide:learn_bind:bind_vars|bind variable SQL statement execution]], to produce injection resistant code.
 +
 +On RDBMS with positional (numbered) query parameters such as PostgreSQL, calling ''param(false)'' will reset the parameter counter, allowing to start building a new query.
 +
 ------------------------------ ------------------------------
 ===== Usage ===== ===== Usage =====
 +
 +This is an example of how to use param() to build SQL queries:
 +
 <code php> <code php>
-/+$sql1 = 'SELECT FROM accounts WHERE '  
-* Connection to Oracle database +    . 'name = ' $db->param('account') . ' AND ' 
-*/ +    . 'total = ' . $db->param('amount'); 
-print $db->param('account'); + 
-/* +$db->param(false); // Reset param count 
-prints ':account' +$sql2 = 'SELECT FROM accounts WHERE id = . $db->param('id');
-*/+
 </code> </code>
-<code php> + 
-/* +See below for the code's output with various database drivers. 
-* Connection to IBM DB2 database + 
-*/ +==== MySQL, IBM DB2 ==== 
-print $db->param('account'); +<code> 
-/* +$sql1: SELECT FROM accounts WHERE name = ? AND total = ? 
-prints ? +$sql2: SELECT * FROM accounts WHERE id = ? 
-*/+</code> 
 + 
 +==== Oracle (oci8==== 
 +<code> 
 +$sql1: SELECT FROM accounts WHERE name = :account AND total = :amount 
 +$sql2: SELECT FROM accounts WHERE id = :id" 
 +</code> 
 + 
 +==== PostgreSQL ==== 
 +<code> 
 +$sql1: SELECT * FROM accounts WHERE name = $1 AND total = $2 
 +$sql2: SELECT * FROM accounts WHERE id = $1
 </code> </code>
  
v5/reference/connection/param.txt · Last modified: 2021/02/26 01:35 by dregad