PHP and ndbm question

From: Date: Mon, 25 Sep 2000 22:32:37 +0000
Subject: PHP and ndbm question
Groups: php.db 
Request: Send a blank email to php-db+get-3063@lists.php.net to get a copy of this message
Greetings all, Well I've been beating my head against the wall on this one for about a week now. I like to think I finally figured it out and now I've run into a problem. I'm using php to read a csv text file of about 100 records with headers as first row into a ndbm db. The school is running php 3.0.12 on Solaris 5.6. dblist reports ndbm supported. I have been using the dbm functions to access the db I'm creating. The db is used on two subsequent pages to show a listing of all jobs available and the specific job details. sample file only has 16 records and a fle size of 30k. Everything runs smoothly, except the dbmreplace or dbminsert commands. No error messages are reported, but when assigning the function to a var, the var echos as -1 for both dbmreplace or dbminsert. Db is created with 0 length. Currently baffled by lack of success in writing records to db. It had seemed to be working previously, but would only write the first record which was causing a db of 1024 in length. Not exactly sure what change has resulted in problem with code. I want to pass the db key to the third page to use with dbmfetch to retrieve the serialized array, for the specifics about the job selected. I tried it as a query string but it didn't seem to come in as a variable. From a book I'd purchased I understand how variables are automatically available to a receiving script from a form action, but it doesn't elaborate on the details when not using forms. echo "<a href='career_opportunity.php3?id=<? echo($data["Id"); ?>'>".$data["Company_Name"]."</a><br><$ Seeing as the db is no longer working properly, I find it hard to test the subsequent pages. I had hoped the code above would work. The code of populatedb.php3 file follows below. I'd hoped to deploy the pages tomorrow. This being my first foray into php I find my own ignorance to be holding me back, any insight would greatly be appreciated. page can be found at http://www.umanitoba.ca/management/groups/umtollef/csc/populatedb.php3 ********** populatedb.php3 ******************8 <?php $filename = "postings.txt"; $dbpath = "webdb"; function import_text() { global $filename, $dbpath; $db = dbmopen($dbpath, "n"); if (!$db) { echo "db open failed"; echo "Program terminated"; } $fp = fopen($filename, "r"); if(!$fp) { dbmclose($db); echo "Cannot open job postings text file $filename"; } $stringkeys = fgetcsv($fp, 1000); while (list ($key, $var) = each ($stringkeys) ) { echo "$key &nbsp; $var <br>"; } echo "<br><br>"; $id = 1; echo "$id is the next id in dbofpostings db<br><br>"; while(!feof($fp)) { $data = fgetcsv($fp, 100000); if(is_array($data) && count($data) > 0 ) { $new = array(); for($i = 0; $i < count($data); $i++) { $new[$stringkeys[$i]] = $data[$i]; } $new["Id"] = $id; while (list ($key, $var) = each ($new) ) { echo "$key &nbsp; $var<br>"; } $replacedb = dbminsert($db, $id, serialize($new)); echo "$replacedb - bool check 0 success, -1 fail"; echo "<br><br>"; $id++; } } fclose($fp); dbmclose($db); ?> Geoff Tollefson (204)474-6739 umtollef@cc.umanitoba.ca gtollef@hotmail.com

« previous php.db (#3063) next »