Jump to content

Archived

This topic is now archived and is closed to further replies.

Grayda

ADOdb GetAssoc() and numerical indexes

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!

Share this post


Link to post
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 :)

Share this post


Link to post
Share on other sites

×
×
  • 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.