Home > Backend Development > PHP Tutorial > Problem with phalcon database module

Problem with phalcon database module

WBOY
Release: 2016-08-04 09:19:49
Original
1264 people have browsed it

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

Reply content:

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:

Problem with phalcon database module

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>
Copy after login

Secondly, the query method itself returns an object instance. This is explained in the document, and it also explains how to return an array:

Problem with phalcon database module

Here I will give you another sample code:

<code class="php">        $result = $connection -> query($sql);
        $result -> setFetchMode(Db::FETCH_ASSOC);
        $array = $result -> fetchAll();</code>
Copy after login

Friendly reminder: read more documents:)

Reference document: link description
link description

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template