Execute an SQL statement using Prepared Statements.
|$sql:||The MySQL query to perform on the database|
|$varN:||The variable(s) that will be placed instead of the ? placeholder separated by a ‘,’ or it can be the method Prepare.|
Like the Execute Method, in most cases you probably only use this method when Inserting or Updating data for retrieving data you can use:
|PgetAll||Executes the SQL and returns the all the rows as a 2-dimensional array.|
|PgetRow||Executes the SQL and returns the first row as an array.|
|PgetCol||Executes the SQL and returns all elements of the first column as a 1-dimensional array.|
|PgetOne||Executes the SQL and returns the first field of the first row.|
|PgetASSOC||Executes the SQL and returns an associative array for the given query. If the number of columns returned is greater to two, a 2-dimensional array is returnedwith the first column of the recordset becomes the keys to the rest of the rows. If the columns is equal to two, a 1-dimensional array is created, where the the keys directly map to the values.|
Notice that when using “Prepared statements” the methods are prefixed with a P.
1 2 3 4 5 6 7 8 9 10 11 12
<?php require_once 'dalmp.php'; $user = getenv('MYSQL_USER') ?: 'root'; $password = getenv('MYSQL_PASS') ?: ''; $DSN = "utf8://$user:$firstname.lastname@example.org/test"; $db = new DALMP\Database($DSN); $db->PExecute('SET time_zone=?', 'UTC');
An Insert example:
1 2 3
<?php $db->PExecute('INSERT INTO mytable (colA, colB) VALUES(?, ?)', rand(), rand());
An Update example:
1 2 3
<?php $db->PExecute('UPDATE Country SET code=? WHERE Code=?', 'PRT', 'PRT');
When updating the return value 0, Zero indicates that no records where updated.
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