I'm trying to store an array of objects in a dbm database.  
Here's what I'm using:
function build_preliminary_language_index($lang, $db, $key) {
$dbh = dbmopen("$db", "c") 
        or die("Error opening db");
$article_string = dbmfetch($dbh, "articles");
$article_array = unserialize($article_string);
$lang_index = array();
for($i=0; $i < sizeof($article_array); $i++) {
  if(stripslashes($article_array[$i]->get_lang()) == "$lang") {
    array_push($lang_index, $article_array[$i]);
  }
}
$lang_string = serialize($lang_index);
dbmreplace($dbh, "$key", "$lang_string");
dbmclose($dbh)
}

Which seems to work nicely.  I was able to grab the newly 
created array "$lang_string" from another page and output the 
information easily.  The problem is I'm grabbing the new array 
and manipulating it with another function below and it keeps 
tacking on a NULL as the first element of the array:

Here's some debugging output and the error on the html page:
array
$article_array[0] = NULL
$article_array[1] = object

Fatal error: Call to a member function on a non-object in 
/home/jesse/public_html/newbiedoc/devel/index.es.phtml on line 
205

Line 205 is where the objects start getting utilized and it 
barfs on the NULL.  Here's the function I'm calling to 
manipulate the array of objects after it has been created and 
inserted in the database:

function build_language_specific_index($lang, $db, $key) {
    error_reporting(E_ALL);
    $dbh = dbmopen("$db", "c")
        or die("Error opening db.");
    $lang_string = dbmfetch($dbh, "$key");
    $en_string = dbmfetch($dbh, "en_index");

    $lang_index = unserialize($lang_string);
    $en_index = unserialize($en_string);

    $size_lang_index = sizeof($lang_index);
    $size_en_index = sizeof($en_index);

    for($i=0; $i < $size_lang_index; $i++) {
        for($j=0; $j < $size_en_index; $j++) {
           if($lang_index[$i]->get_aid() !=     
                $en_index[$j]->get_aid()) {
                array_push($lang_index, $en_index[$j]);
           }
        }
    }
    $lang_string = serialize($lang_index);
    dbmreplace($dbh, "$key", "$lang_string");
    dbmclose($dbh);
}

I realize that MySQL or a rdbms would probably solve all these 
issues but I don't have that option yet.  I do have the class 
definition included in both the pages so that doesn't seem to be 
an issue.  I have read the information on serialized objects but 
I confess that I'm not grasping it all that well.  Any help 
would be greatly appreciated.

Thanks,
Jesse


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to