The company did not use the class library provided by phalcon to operate databases, but encapsulated it again with PhalconDbAdapterPdoMysql. However, I found that there are many methods that have problems. please help me, for example, $ statement $ db-& amp; gt; prepare (& #039; SELECT * FROMrobotsWHEREname... the company did not use the class library for database operations provided by phalcon, but encapsulated it again with PhalconDbAdapterPdoMysql. However, I found that there are many problems with the methods. 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 is not running, and errors always occur in the value.
And this
$ Resultset = $ connection-> query ("SELECT * FROM robots WHERE type = 'mechanical '");
$ Resultset = $ connection-> query ("SELECT * FROM robots WHERE type =? ", Array (" mechanical "));
The returned result is not an array, but it does not indicate that the result set of the array can be retrieved again by means of instructions.
Wait... The above examples are from official documents.
Reply content:
The company did not use the class library for database operations provided by phalcon, but encapsulated it again with PhalconDbAdapterPdoMysql. However, I found that there are many problems with the methods. 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 is not running, and errors always occur in the value.
And this
$ Resultset = $ connection-> query ("SELECT * FROM robots WHERE type = 'mechanical '");
$ Resultset = $ connection-> query ("SELECT * FROM robots WHERE type =? ", Array (" mechanical "));
The returned result is not an array, but it does not indicate that the result set of the array can be retrieved again by means of instructions.
Wait... The above examples are from official documents.
First, the placeholder of the "executePrepared" method should be numeric. For example, the English text in the red box of the document:
That is, replace the parameter binding placeholder in your SQL statement with "?". As follows:
$statement=$db->prepare('SELECT * FROM robots WHERE name = ?'); $result=$connection->executePrepared($statement, array('Voltron'));
Second, the query method itself returns an object instance, which is described in this document and the method of returning an array:
Here I will give you another sample code:
$result = $connection -> query($sql); $result -> setFetchMode(Db::FETCH_ASSOC); $array = $result -> fetchAll();
Friendly reminder: read more documentation :)
Reference: link description
Link description