<HTML>
<HEAD>
<TITLE>PHP test script: MUSIC</TITLE>
</HEAD>
<?
ob_implicit_flush();
?>
<BODY>
<H1>PHP test script: MUSIC</H1>
<H3>
<I>Testing:</I><BR>
$db = mpe_dbopen("MUSIC.DATA","MGR",1)
</H3>
<?php
$db = mpe_dbopen("MUSIC.DATA","MGR",1);
if($db != 0)
print "<P>Opened OK</P>";
?>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbfind($db, "SELECTIONS", "ALBUMCODE", 2001)
</H3>
<?php
if(mpe_dbfind($db, "Selections", "albumcode", 2001))
print "<P><I>Found</I></P>";
else
print "<P><B>NOT FOUND</B></P>";
?>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget($db, "SELECTIONS", DBGET_MODE_CHAINED_READ)
<I>and</I><BR>
mpe_dbresult_assoc($db, "SELECTIONS");
</H3>
<TABLE>
<TR>
<?php
$s = mpe_dbinfo_list_items($db,"SELECTIONS");
foreach($s as $x => $y)
print "<TH>$x</TH>\n";
?>
</TR>
<?php
while (mpe_dbget($db, "SELECTIONS", DBGET_MODE_CHAINED_READ))
{
$r = mpe_dbresult_assoc($db, "SELECTIONS");
print("<TR>\n");
foreach($r as $x)
print " <TD>$x</TD>\n";
print("</TR>\n");
}
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget($db, "Composers", DBGET_MODE_SERIAL_READ)
<I>and</I><BR>
mpe_dbresult_assoc($db, "Composers");
</H3>
<TABLE>
<TR>
<?php
$s = mpe_dbinfo_list_items($db,"Composers");
foreach($s as $x => $y)
print "<TH>$x</TH>\n";
?>
</TR>
<?php
while (mpe_dbget($db, "Composers", DBGET_MODE_SERIAL_READ))
{
$r = mpe_dbresult_assoc($db, "Composers");
print("<TR>\n");
foreach($s as $x => $y)
print " <TD>$r[$x]</TD>\n";
print("</TR>\n");
}
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget($db, "albums", DBGET_MODE_CALCULATED_READ, 2003)
<I>and</I><BR>
mpe_dbresult_item($db, "albums", field names);
</H3>
<TABLE>
<TR>
<?php
$s = mpe_dbinfo_list_items($db,"albums");
foreach($s as $x => $y)
print "<TH>$x</TH>\n";
?>
</TR>
<?php
if (mpe_dbget($db, "albums", DBGET_MODE_CALCULATED_READ, 2003))
{
print("<TR>\n");
foreach($s as $x => $y)
{
$r = mpe_dbresult_item($db, "albums", $x);
print " <TD>$r</TD>\n";
}
print("</TR>\n");
}
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbinfo_entry_count($db, "SELECTIONS")
</H3>
<P>
<?php
print "Records = <I>" . mpe_dbinfo_entry_count($db, "SELECTIONS") . "</I>\n";
?>
</P>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbinfo_list_sets($db)
<I>and</I><BR>
mpe_dbinfo_list_items($db,setname)
</H3>
<TABLE BORDER=1>
<TR><TH>Set</TH><TH>Item</TH><TH>Type</TH></TR>
<?php
$sets = mpe_dbinfo_list_sets($db);
foreach($sets as $set) {
print "<TR>\n";
$items = mpe_dbinfo_list_items($db,$set);
$i = count($items);
$b = FALSE;
print "<TD ROWSPAN=$i VALIGN='top'>$set</TD>\n";
foreach($items as $item => $type) {
if($b) {
print "<TR>\n";
} else {
$b = TRUE;
}
print "<TD>$item</TD><TD ALIGN='center'>$type</TD>\n</TR>\n";
}
}
unset($items);
unset($sets);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbput($db,"COMPOSERS",array("COMPOSERNAME" => "John Lennon","BIRTH" => "1940","DEATH" => "1980"))
</H3>
<?php
if(mpe_dbput($db,"COMPOSERS",array("COMPOSERNAME" => "John Lennon","BIRTH" => "1940","DEATH" => "1980")))
print "<P><I>Success</I></P>";
else
print "<P><B>FAILED</B></P>";
?>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbupdate($db,"COMPOSERS","John Lennon",array("BIRTHPLACE" => "Liverpool", "COMMENT" => "Beatle"))
</H3>
<?php
$data = array("BIRTHPLACE" => "Liverpool", "COMMENT" => "Beatle");
if(mpe_dbupdate($db,"COMPOSERS","John Lennon",$data))
print "<P><I>Success</I></P>";
else
print "<P><B>FAILED</B></P>";
?>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget_serial($db, "Composers", "BirthPlace")
</H3>
<P>
<?php
$recs = mpe_dbget_serial($db, "Composers", "BirthPlace");
$k = count($recs);
print "Records found = $k\n";
?>
</P>
<TABLE>
<?php
print "<TR>\n";
foreach(array("ComposerName","BirthPlace") as $x)
print "<TH>$x</TH>\n";
print "</TR>\n";
foreach($recs as $key => $item) {
print "<TR>\n<TD>\n$key\n</TD>\n<TD>\n$item\n</TD>\n</TR>\n";
}
unset($recs);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbdelete($db,"COMPOSERS","John Lennon")
</H3>
<?php
if(mpe_dbdelete($db,"COMPOSERS","John Lennon"))
print "<P><I>Success</I></P>";
else
print "<P><B>FAILED</B></P>";
?>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget_serial_back($db, "Albums", NULL, 100)
</H3>
<P>
<?php
$recs = mpe_dbget_serial_back($db, "Albums", NULL, 100);
$k = count($recs);
print "Records found = $k\n";
?>
</P>
<TABLE>
<?php
foreach($recs as $recnum => $rec) {
print "<TR>\n <TD>$recnum</TD>\n";
foreach($rec as $data) {
print " <TD>$data</TD>\n";
}
print "</TR>\n";
}
unset($recs);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget_chain($db, "Selections", "ComposerName", "Franz Schubert", array("SelectionName","Performers"), 100)
</H3>
<P>
<?php
$recs = mpe_dbget_chain($db, "Selections", "ComposerName", "Franz Schubert", array("SelectionName","Performers"), 100);
$k = count($recs);
print "Records found = $k\n";
?>
</P>
<TABLE>
<?php
foreach($recs as $recnum => $rec) {
print "<TR>\n<TD>\n$recnum\n</TD>\n";
foreach($rec as $item) {
print "<TD>\n$item\n</TD>\n";
}
print "</TR>\n";
}
unset($recs);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget_chain_back($db, "Selections", "AlbumCode", 2001, "SelectionName")
</H3>
<P>
<?php
$recs = mpe_dbget_chain_back($db, "Selections", "AlbumCode", 2001, "SelectionName");
$k = count($recs);
print "Records found = $k\n";
?>
</P>
<TABLE>
<?php
foreach($recs as $recnum => $data) {
print "<TR><TD>$recnum</TD><TD>$data</TD></TR>\n";
}
unset($recs);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dbget_chain($db, "Albums", "AlbumCode", 2003, "", 100)
</H3>
<P>
<?php
$recs = mpe_dbget_chain($db, "Albums", "AlbumCode", 2003, "", 100);
$k = count($recs);
print "Records found = $k\n";
?>
</P>
<TABLE>
<?php
foreach($recs as $recnum => $rec) {
print "<TR>\n<TD>\n$recnum\n</TD>\n";
foreach($rec as $item) {
print "<TD>\n$item\n</TD>\n";
}
print "</TR>\n";
}
unset($recs);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dblookup($db, "Albums", "AlbumCode", 2003, "")
</H3>
<P>
<?php
$rec = mpe_dblookup($db, "Albums", "AlbumCode", 2003, "");
?>
</P>
<TABLE>
<?php
foreach($rec as $x => $y) {
print "<TR><TD>\n$x\n</TD>\n<TD>\n$y\n</TD>\n</TR>\n";
}
unset($rec);
?>
</TABLE>
<HR>
<H3>
<I>Testing:</I><BR>
mpe_dblookup($db, "Selections", "AlbumCode", 2003,
array("ComposerName","Performers","SelectionName"))
</H3>
<P>
<?php
$rec = mpe_dblookup($db, "Selections", "AlbumCode", 2003,
array("ComposerName","Performers","SelectionName"));
?>
</P>
<TABLE>
<?php
foreach($rec as $x => $y) {
print "<TR><TD>\n$x\n</TD>\n<TD>\n$y\n</TD>\n</TR>\n";
}
unset($rec);
?>
</TABLE>
<HR>
<H3>
<I>Testing weird data types</I>: The <B>hard</B> way
</H3>
<TABLE>
<?php
$items = mpe_dbinfo_list_items($db,$set);
print "<TR>";
foreach($items as $name => $type) {
print "<TH";
if(preg_match("/(\\d*)([A-Z]\\d+)/",$type)) {
print preg_replace("/(\\d*)([A-Z]\\d+)/"," COLSPAN=\$1",$type);
}
print ">$type</TH>";
}
print "</TR>\n";
while (mpe_dbget($db, "TestSet", DBGET_MODE_SERIAL_READ))
{
print("<TR>");
foreach($items as $name => $type) {
$x = mpe_dbresult_item($db, "TestSet", $name);
if(is_array($x)) {
foreach($x as $subitem) {
print "<TD>$subitem</TD>";
}
} else {
print "<TD>$x</TD>";
}
}
print("</TR>\n");
}
mpe_dbreset($db, "TestSet");
?>
</TABLE>
<HR>
<H3>
<I>Testing weird data types:</I> The <B>easy</B> way
</H3>
<?php
$recs = mpe_dbget_serial($db, "TestSet", "" ,100);
$k = count($recs);
print "Records found = $k\n";
?>
</P>
<TABLE>
<?php
$items = mpe_dbinfo_list_items($db,$set);
print "<TR>\n";
foreach($items as $name => $type) {
print "<TH";
if(preg_match("/(\\d*)([A-Z]\\d+)/",$type)) {
print preg_replace("/(\\d*)([A-Z]\\d+)/"," COLSPAN=\$1",$type);
}
print ">$type</TH>";
}
print "</TR>\n";
unset($items);
foreach($recs as $recnum => $rec) {
print "<TR>";
foreach($rec as $item) {
if(is_array($item)) {
foreach($item as $subitem) {
print "<TD>$subitem</TD>";
}
} else {
print "<TD>$item</TD>";
}
}
print "</TR>\n";
}
unset($recs);
?>
</TABLE>
<HR>
</BODY>
</HTML>