Pear website problem
| From: | Monjur | Date: | Wed, 04 Jan 2006 16:45:00 +0000 |
| Subject: | Pear website problem | ||
| Groups: | php.pear.webmaster | ||
| Request: | Send a blank email to pear-webmaster+get-4687@lists.php.net to get a copy of this message | ||
Hi,
I'm developing a website with PEAR DB with HTTP authentication. I'm
quite new to PearDB. Please solve this with explanation so that I can
solve my problem.
Thanks in advance
Monjur.
##==================Here is my Code===========================##
<?php
require_once("Auth.php");
$AuthOptions = array(
'dsn'=>"mysql://uname:upass@localhost/db",
'table'=>"admin",
'usernamecol'=>"adminID",
'passwordcol'=>"password",
'cryptType'=>"none",
'db_fields'=>"*" // Collecting Other DB fields
);
$a = new Auth_HTTP("DB", $AuthOptions);
$a->setRealm('Please enter UserName & Password !!!');
$a->setCancelText('<h2>Authentication Failure</h2>');
$a->start();
if($a->getAuth())
{
echo "Hello <b>$a->username</b> welcome to your personal page
<BR><BR>";
echo "<a href=admin.php?action=archive>Archive the database file</a>";
if($_GET['action'] == "archive") ArchiveData();
};
function ArchiveData()
{
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement( "parentEle" );
$doc->appendChild( $r );
/*-----------------------------Get Data From
DB---------------------------------*/
// $dbType = "oci8";
$dbType = "mysql";
if ($dbType == "mysql"){
$dsn = $dbType."://root:@localhost/dbName";
} else {
$dsn = $dbType."://root:password@dbName";
}
$db = DB::connect($dsn);
if (DB::iserror($db)){
die($db->getMessage());
}
$db->setFetchMode(DB_FETCHMODE_ASSOC);
$qry = $db->query("SELECT * FROM tName");
if (DB::iserror($qry)){
die($qry->getMessage());
}
while($row = $qry->fetchRow()){
$parentEle[] = array(
'bookingref' => "$row[bookingRef]",
'customerid' => "$row[customerID]",
'bookingtype' => "$row[bookingType]",
'typeno' => "$row[typeNo]",
'startdate' => "$row[startDate]",
'starttime' => "$row[startTime]",
'enddate' => "$row[endDate]",
'endtime' => "$row[endTime]",
'stationstart' => "$row[stationStart]",
'stationend' => "$row[stationEnd]",
'peopleno' => "$row[peopleNo]",
'netprice' => "$row[netPrice]"
);
} // END WHILE
$qry->free();
$db->disconnect();
/*------------------------------------------------------------------------------*/
foreach( $activities as $activity ){
$b = $doc->createElement( "booking" );
$bookingref = $doc->createElement( "bookingref" );
$bookingref->appendChild(
$doc->createTextNode( $activity['bookingref'] )
);
$b->appendChild( $bookingref );
$customerid = $doc->createElement( "customerid" );
$customerid->appendChild(
$doc->createTextNode( $activity['customerid'] )
);
$b->appendChild( $customerid );
$bookingtype = $doc->createElement( "bookingtype" );
$bookingtype->appendChild(
$doc->createTextNode( $activity['bookingtype'] )
);
$b->appendChild( $bookingtype );
$typeno = $doc->createElement( "typeno" );
$typeno->appendChild(
$doc->createTextNode( $activity['typeno'] )
);
$b->appendChild( $typeno );
$startdate = $doc->createElement( "startdate" );
$startdate->appendChild(
$doc->createTextNode( $activity['startdate'] )
);
$b->appendChild( $startdate );
$starttime = $doc->createElement( "starttime" );
$starttime->appendChild(
$doc->createTextNode( $activity['starttime'] )
);
$b->appendChild( $starttime );
$enddate = $doc->createElement( "enddate" );
$enddate->appendChild(
$doc->createTextNode( $activity['enddate'] )
);
$b->appendChild( $enddate );
$endtime = $doc->createElement( "endtime" );
$endtime->appendChild(
$doc->createTextNode( $activity['endtime'] )
);
$b->appendChild( $endtime );
$stationstart = $doc->createElement( "stationstart" );
$stationstart->appendChild(
$doc->createTextNode( $activity['stationstart'] )
);
$b->appendChild( $stationstart );
$stationend = $doc->createElement( "stationend" );
$stationend->appendChild(
$doc->createTextNode( $activity['stationend'] )
);
$b->appendChild( $stationend );
$peopleno = $doc->createElement( "peopleno" );
$peopleno->appendChild(
$doc->createTextNode( $activity['peopleno'] )
);
$b->appendChild( $peopleno );
$netprice = $doc->createElement( "netprice" );
$netprice->appendChild(
$doc->createTextNode( $activity['netprice'] )
);
$b->appendChild( $netprice );
$r->appendChild( $b );
} //END FOREACH
$doc->save("./xmldata/booking.xml");
}
?>
##============================================================##