homepage Welcome to WebmasterWorld Guest from 54.198.224.121
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php simple database - I'm a bit lost
kapow




msg:1301223
 3:12 pm on Oct 15, 2001 (gmt 0)

Any chance of a bit of php guidence?

I am writing a php application to: dispaly and modify a non-relational database ie from a simple text file of some kind. I am still very much a beginner to php and have copied and adapted my code from a book. When I test the code (by clicking the 'Overview' button I get the following message:

Fatal error: Call to unsupported or undefined function dba_open() in /usr/www/users/myname/myfolder/index.php3 on line 70

My fist draft code is included below in case it helps you see what I'm trying to do). The site is hosted with Pair.com. I have set access permissions (for the file database.db) to 777.

-------------------
My first draft code
-------------------

<html>
<head>
<title>Database Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<? function display_menu() { ?>
<FORM ENCTYPE="multipart/form-data">
<INPUT TYPE=SUBMIT NAME=action VALUE=" New Entry "> 
<INPUT TYPE=SUBMIT NAME=action VALUE=" Overview "> 
Search: <INPUT TYPE=TEXT NAME=word>
<INPUT TYPE=SUBMIT NAME=action VALUE=" Search "> 
</FORM>
<? } ?>

<? function display_entry($data) { ?>
<B>Hotel <? echo($data["name"]); ?></B><P>
Single Cost <? echo($data["singlecost"]); ?><P>
Double Cost <? echo($data["doublecost"]); ?><P>
Valid Dates <? echo($data["validdates"]); ?><P>
<? } ?>

<? function overview_start() { ?>
<FORM>
<TABLE>
<TR>
<TH>Name</TH>
<TH>Selection</TH>
</TR>
<? } ?>

<? function overview_entry($data) { ?>
<TR>
<TD><?echo $data["name"]?></TD>
<TD><INPUT TYPE=RADIO NAME=id VALUE="<?echo $data["id"]?>"></TD>
</TR>
<? } ?>

<? function overview_end() { ?>
</TABLE>
<INPUT TYPE=SUBMIT NAME=action VALUE=" Edit ">
<INPUT TYPE=SUBMIT NAME=action VALUE=" View ">
<INPUT TYPE=SUBMIT NAME=action VALUE=" Delete ">
</FORM>
<? } ?>

<? function action_view($id) {
global $dbpath, $dbtype;
$db = dba_open($dbpath, "r", $dbtype);

if (!$db) {
echo "Database open failed";
return;
}

$value = dba_fetch($id, $db);
$data = unserialize($value);

dba_close($db);

display_entry($data);
} ?>

<? function action_overview() {
global $dbpath, $dbtype;
$db = dba_open($dbpath, "r", $dbtype);

if (!$db) {
echo "Database open failed";
return -1;
}

overview_start();
$key = dba_firstkey($db);

while ($key != false) {
$value = dba_fetch($key, $db);
$entry = unserialize($value);
overview_entry($entry);
$key = dba_nextkey($db);
}

overview_end();
dba_close($db);
} ?>

<? function edit_form($data) { ?>
<FORM>
<INPUT TYPE=HIDDEN NAME="action" VALUE="update">
<INPUT TYPE=HIDDEN NAME="id" VALUE="<? echo($data["id"]); ?>">
Hotel: <INPUT TYPE=TEXT NAME=hotel VALUE="<? echo($data["hotel"]); ?>"><P>
Single Cost: <INPUT TYPE=TEXT NAME=singlecost VALUE="<? echo($data["singlecost"]); ?>"><P>
Double Cost: <INPUT TYPE=TEXT NAME=doublecost VALUE="<? echo($data["doublecost"]); ?>"><P>
Valid Dates: <INPUT TYPE=TEXT NAME=validdates VALUE="<? echo($data["validdates"]); ?>"><P>
<INPUT TYPE=SUBMIT VALUE=" OK ">
</FORM>
<? } ?>

<? function action_edit($id) {
global $dbpath, $dbtype;
$db = dp_open($dbpath, "r", $dbtype);

if (!$db) {
echo "Database open failed";
return;
}
$value = dba_fetch($id, $db);
$data = unserialize($value);

dba_close($db);
edit_form($data);
} ?>

<? function action_update($data) {
global $dbpath, $dbtype;
$db = dp_open($dbpath, "c", $dbtype);

if (!$db) {
echo "Database open failed";
return;
}
dba_replace($data["id"], serialize($data), $db);
$data = unserialize($value);
dba_sync($db);
dba_close($db);
} ?>

<? function action_new() {
global $dbpath, $dbtype;
if(is_file($dbpath)) {
$db = dp_open($dbpath, "r", $dbtype);
} else {
$db = dp_open($dbpath, "c", $dbtype);
}
if (!$db) {
echo "Database open failed";
return;
}
$data = array();
$data["id"] = get_next_id($db);

dba_close($db);
edit_form($data);
} ?>

<? function get_next_id($db) {
$max_id = 0;

$key = dba_firstkey($db);
while ($key != false) {
if ($key > $max_id) {
$max_id = $key;
}
$key = dba_nextkey($db);
}
return $max_id + 1;
} ?>

<?
// path to database
$dbpath = "database.db";

// database type
$dbtype = "gdbm";

$data = array();
$vars = array("hotel","singlecost","doublecost","validdates","id");

for($i = 0; $i < count($vars); $i++) {
$data[$vars[$i]] = ${$vars[$i]};
}

display_menu();

$action = strtolower(trim($action));

switch($action){

case "view":
action_view($id);
break;

case "overview":
action_overview();
break;
} ?>

</body>
</html>

 

ggrot




msg:1301224
 4:12 pm on Oct 15, 2001 (gmt 0)

Somewhere you need to define the function dba_open. The adapted code you are using probably provides this function somewhere else in the book/cd. Look around for it and include it in your source.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved