Utherr12 Posted March 4, 2011 Share Posted March 4, 2011 function db_init() { $db = NewADOConnection(pref_getServerPreference('database')); if (!$db) { die("Connection failed"); } ADOdb_Active_Record::SetDatabaseAdapter($db); $db->Execute('set names utf8'); $GLOBALS['db'] = $db; $db->debug = true; //just for debug}function db_changeDatabase($dbName) { $dbName = addslashes($dbName); db_init(); return logged_query("use $dbName");}function db_getArrayAssoc($query) { return $GLOBALS['db']->GetAssoc($query);} echo db_changeDatabase('DEX');$max_words = db_getSingleValue("SELECT COUNT(*) as words FROM `Definition`");echo $random_w = rand(0,$max_words);$WordWithID = db_getArrayAssoc("SELECT * FROM `Definition` WHERE `id`='$random_w'");echo "<br /><br />".$WordWithID; The above piece of code doesn't work /facepalm. $WordWithID returns "Array". Link to comment Share on other sites More sharing options...
Synook Posted March 4, 2011 Share Posted March 4, 2011 That's becase $WordWithID is an array - when you echo an array, it prints "Array". Link to comment Share on other sites More sharing options...
Utherr12 Posted March 4, 2011 Author Share Posted March 4, 2011 Ok then... how does GetAssoc() returns the array? Obviously it doesn't work like mysql_fetch_assoc. foreach ($WordWithID as $content ) echo $content; Displays ArrayArray. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2011 Share Posted March 4, 2011 It probably returns a multidimensional array of rows. You can use print_r or var_dump to find out. In order to figure out exactly what the function does we would need to look at the code for it. Link to comment Share on other sites More sharing options...
Starfall Posted March 7, 2011 Share Posted March 7, 2011 GetAssoc just works like mysql_fetch_assoc...Set the variable $ADODB_FETCH_MODE to ADODB_FETCH_ASSOC constant and then just output $wordWithID["rowyouwanttoecho"]. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.