After execute below code, twice record added in my table.
$config = new \Phalcon\Config([
'database' => [
]
]);
$di = new FactoryDefault();
$di->setShared('db', function () use ($config) {
$dbConfig = $config->database->toArray();
$adapter = $dbConfig['adapter'];
unset($dbConfig['adapter']);
$class = 'Phalcon\Db\Adapter\Pdo\\' . $adapter;
return new $class($dbConfig);
});
**$di->get('db')->query("INSERT INTO dbname.table VALUES ('', '');")->execute();**
Query and execute are both executing sql statement. query method returns statement/result object which can be executed again.
@sergeyklay close it as not a bug
execute() -> Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server doesn鈥檛 return any rows
query() -> Sends SQL statements to the database server returning the success state. Use this method only when the SQL statement sent to the server is returning rows
@stamster well you missed that query return other object than db adapter, i first thought the same, but still, object returned have execute method too - so generally speaking he just executes two times query.
Most helpful comment
Query and execute are both executing sql statement. query method returns statement/result object which can be executed again.
@sergeyklay close it as not a bug