Cphalcon: Twice Insert db service

Created on 21 Jun 2017  路  3Comments  路  Source: phalcon/cphalcon

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();**

Details

  • Phalcon version: 3.2.0
  • PHP Version: 7
  • Operating System: Ubuntu
  • Server: Nginx

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

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sharptry picture sharptry  路  3Comments

Yakovlev-Melarn picture Yakovlev-Melarn  路  3Comments

hesalx picture hesalx  路  4Comments

alvassin picture alvassin  路  3Comments

fonqing picture fonqing  路  3Comments