Prepare¶
Prepare arguments for the Prepared Statements PExecute method.
Parameters¶
Prepare($arg= null)
$arg: | Argument to be used in the PExecute method, if no input it will return the array with the prepared statements. |
---|
The prepare method automatically detect the input type, you can also override this, using something like:
Prepare('s','1e1')
Example¶
Building dynamic queries that require prepared statements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php
require_once 'dalmp.php';
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$x = 3;
$id = 1;
$db->Prepare($id)
$sql = 'SELECT * FROM test WHERE id=?';
if ($x == 3) {
$db->Prepare($x);
$sql .= 'AND id !=?';
}
$db->Prepare('s', 'colb');
$sql .= 'AND colB=?';
/**
* this will produce a query like:
* SELECT * FROM test WHERE id=? AND id !=? AND colB=?
* with params = ["iis",1,3,"colb"]
*/
$rs = $db->PgetAll($sql, $db->Prepare());
|
See also
A great amount of time has been spent creating, crafting and maintaining this software, please consider donating.
Donating helps ensure continued support, development and availability.
comments powered by Disqus