Execute¶
Execute an SQL statement, returns true on success, false if there was an error in executing the sql.
Parameters¶
Execute($sql)
$sql: | The MySQL query to perform on the database. |
---|
In most cases you only use this method when Inserting or Updating data, for retrieving data the 5 common methods are:
Name | Normal | Prepared Statements | Cache Normal | Cache Prepared Statements |
---|---|---|---|---|
all | GetAll | PGetAll | CacheGetAll | CachePGetAll |
assoc | GetAssoc | PGetAssoc | CacheGetAssoc | CachePGetAssoc |
col | GetCol | PGetCol | CacheGetCol | CachePGetCol |
one | GetOne | PGetOne | CacheGetOne | CachePGetOne |
row | GetRow | PGetRow | CacheGetRow | CachePGetRow |
See also
Examples¶
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:$password".'@127.0.0.1/test';
$db = new DALMP\Database($DSN);
$rs = $db->Execute("INSERT INTO table (name,email,age) VALUES('name', 'email', 70)");
|
You can also catch exception and continue execution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php
require_once 'dalmp.php';
$user = getenv('MYSQL_USER') ?: 'root';
$password = getenv('MYSQL_PASS') ?: '';
$DSN = "utf8://$user:$password".'@127.0.0.1/test';
$db = new DALMP\Database($DSN);
try {
$db->Execute('CREATE TABLE myCity LIKE City');
} catch (Exception $e) {
echo "Table already exists.",$db->isCli(1);
}
$db->Execute("INSERT INTO myCity VALUES (NULL, 'Toluca', 'MEX', 'México', 467713)");
|
Thanks Navicat for supporting Open Source projects.
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