-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFR] Implement PDO::FETCH_GROUP in Phalcon\Db #1642
Comments
Like this: $result->setFetchMode(Phalcon\Db::FETCH_COLUMN | Phalcon\Db::FETCH_GROUP);
$result->setFetchMode(Phalcon\Db::FETCH_ASSOC | Phalcon\Db::FETCH_GROUP); |
@le51 this has been implemented in both 1.2.5 and 1.3.0, could you please check? |
Hi, thank you for reactivity ... but I've just downloaded last 1.3.0 with:
and your PR aren't in there. Am I missing something ? |
Please build from ext/: cd ext
git checkout 1.3.0
phpize
./configure
make
sudo make install |
Oh Ok, It's been a while since I was asking myself on how to build the different branch of phalcon. I've learned something helpfull today !!! Thank you So, with Phalcon\Db::FETCH_GROUP, I've tested it:
But it doesn't output the expected array (grouped by "ville" name as the given link above said):
By the way, I've tested the raw example:
And result is as expected:
(I've modify the names to keep users "anonymous, so lengths are not the good one !) |
OK looking |
Looks like the issue is how Phalcon implements I have updated the implementation to use diff --git a/ext/db/adapter.c b/ext/db/adapter.c
index 1efb5a2..924e76b 100644
--- a/ext/db/adapter.c
+++ b/ext/db/adapter.c
@@ -264,8 +264,7 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchOne){
PHP_METHOD(Phalcon_Db_Adapter, fetchAll){
zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL;
- zval *result, *row = NULL;
- zval *r0 = NULL;
+ zval *result;
PHALCON_MM_GROW();
@@ -284,26 +283,14 @@ PHP_METHOD(Phalcon_Db_Adapter, fetchAll){
bind_types = PHALCON_GLOBAL(z_null);
}
- array_init(return_value);
-
PHALCON_INIT_VAR(result);
phalcon_call_method_p3(result, this_ptr, "query", sql_query, bind_params, bind_types);
if (likely(Z_TYPE_P(result) == IS_OBJECT)) {
if (Z_TYPE_P(fetch_mode) != IS_NULL) {
phalcon_call_method_p1_noret(result, "setfetchmode", fetch_mode);
}
-
- while (1) {
-
- PHALCON_INIT_NVAR(r0);
- phalcon_call_method(r0, result, "fetch");
- PHALCON_CPY_WRT(row, r0);
- if (!zend_is_true(row)) {
- break;
- }
-
- phalcon_array_append(&return_value, row, 0);
- }
+
+ phalcon_return_call_method_p0(result, "fetchall");
}
PHALCON_MM_RESTORE(); |
Hi, sjinks I've tried your fix, but I'm still getting the same result (as above) ... ---- OFF TOPIC ---- |
#1642: use fetchAll() instead of fetch() in Phalcon\Db\Adapter::fetchAll()
Phalcon's implementation corresponds to this: $dbh = new PDO('mysql:host=localhost;dbname=phalcon_test', 'user', 'pass');
$query = $dbh->query("SELECT email, nombres FROM personas");
$query->setFetchMode(PDO::FETCH_ASSOC | PDO::FETCH_GROUP);
$result = $query->fetchAll();
print_r($result); That is, fetch options are set by I'll check what can be done here. |
Got a bit confused by the commits around Phalcon\Db::FETCH_GROUP work. Is grouping currently supported by Phalcon or is it still under development? Thanks! |
Hi, Have a nice day. |
Under development |
This feature allows you to get associated formatted arrays in a really simple manner.
Some exemples here:
http://forum.phpfrance.com/vos-contributions/affichage-par-categorie-avec-pdo-t254289.html
It's in french, but code is clear.
The text was updated successfully, but these errors were encountered: