Home > Article > Backend Development > Problem with phalcon database module
The company did not use the class library provided by phalcon to operate the database, but used PhalconDbAdapterPdoMysql to encapsulate it again. However, I found that many methods in it have problems. Please help me.
For example
$statement = $db->prepare('SELECT * FROM robots WHERE name = :name');
$result = $connection->executePrepared($statement, array('name' => 'Voltron') );
This piece of code does not run smoothly and always reports an error with wrong value
And this one
$resultset = $connection->query("SELECT * FROM robots WHERE type='mechanical'");
$resultset = $connection->query("SELECT * FROM robots WHERE type=?" , array("mechanical"));
What is returned is not an array, but there is no explanation that the result set of the array can be retrieved again using the explanation method
Anyway, just wait. . . The above examples are all from official documents
The company did not use the class library provided by phalcon to operate the database, but used PhalconDbAdapterPdoMysql to encapsulate it again. However, I found that many methods in it have problems. Please help me.
For example
$statement = $db->prepare('SELECT * FROM robots WHERE name = :name');
$result = $connection->executePrepared($statement, array('name' => 'Voltron') );
This piece of code does not run smoothly and always reports an error with wrong value
And this one
$resultset = $connection->query("SELECT * FROM robots WHERE type='mechanical'");
$resultset = $connection->query("SELECT * FROM robots WHERE type=?" , array("mechanical"));
What is returned is not an array, but there is no explanation that the result set of the array can be retrieved again using the explanation method
Anyway, just wait. . . The above examples are all from official documents
First of all, the placeholder of the "executePrepared" method should be numeric. As in English in the red box of the document:
That is, the parameter binding placeholder in your SQL should be replaced with "?", as follows:
<code class="php"> $statement=$db->prepare('SELECT * FROM robots WHERE name = ?'); $result=$connection->executePrepared($statement, array('Voltron'));</code>
Secondly, the query method itself returns an object instance. This is explained in the document, and it also explains how to return an array:
Here I will give you another sample code:
<code class="php"> $result = $connection -> query($sql); $result -> setFetchMode(Db::FETCH_ASSOC); $array = $result -> fetchAll();</code>
Friendly reminder: read more documents:)
Reference document: link description
link description