Grayda Posted August 3, 2009 Share Posted August 3, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/168588-adodb-getassoc-and-numerical-indexes/ Share on other sites More sharing options...
Grayda Posted August 10, 2009 Author Share Posted August 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168588-adodb-getassoc-and-numerical-indexes/#findComment-894424 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.