Jump to content

ADOdb GetAssoc() and numerical indexes


Grayda

Recommended Posts

I'm rather confused here. I'm using ADOdb (the database abstraction library, [link url=http://adodb.sf.net]ADOdb on SF.net[/link]) to grab some data out of a table as an associative array. My code looks like this:

 

<?php

require("./adodb5/adodb.inc.php");

$db = &ADONewConnection("mysql");
$db->PConnect("localhost", "someone", "password", "myapp");
$data = $db->GetAssoc("SELECT * FROM security", false, true); # Second parameter is binding, third forces the array to be two dimensional, even if the data isn't
echo var_dump($data);

?>

 

And my table has five columns: id, name, access, group and description. ID is a unique ID, name is the name of the security object (eg. news:manageNews), access is what the object can do (eg. news:writeArticle, news:deleteArticle), group is the security group that object belongs to (eg. group:news) and description is obviously, a description (eg. Group that manages news)

 

What I expect to see, is:

 

array(1) { 
[0]=> array(5) { 
["id"]=> string(1) "1" 
["name"]=> string(13) "Administrator" 
["access"]=> string(12) "news:canPost" 
["groups"]=> string(19) "group:administrator" 
["description"]=> string(20) "Administrator Object" }
}

 

But what I get back, is this:

 

array(1) {

[1]=> array(9) {

["id"]=> string(1) "1"

[0]=> string(13) "Administrator"

["name"]=> string(13) "Administrator"

[1]=> string(12) "news:canPost"

["access"]=> string(12) "news:canPost"

[2]=> string(19) "group:administrator"

["groups"]=> string(19) "group:administrator"

[3]=> string(20) "Administrator Object"

["description"]=> string(20) "Administrator Object"

}

[/code]

 

Notice how there's four array items in there with the keys "0", "1", "2" and "3"? This isn't standard ADOdb (or MySQL) behaviour, as the documentation for GetAssoc shows data being returned with no numerical indexes and pasting a "GET * FROM security" into phpMyAdmin AND into the MySQL command line returns the data without the numerical indexes

 

Is there a flag I'm missing here? Something I'm not doing with my database? Cheers!

Link to comment
Share on other sites

I've managed to solve my problem. Turns out I needed to call $db->SetFetchMode(ADODB_FETCH_ASSOC) before connecting. I thought GetAssoc would do that for me, but it kept the FetchMode as ADODB_FETCH_DEFAULT.

 

Hope this helps someone else out there :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.