Jump to content

AdoDB problem


Utherr12

Recommended Posts

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

That's becase $WordWithID is an array - when you echo an array, it prints "Array".

Link to comment
Share on other sites

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

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

Archived

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

×
×
  • Create New...