From a real newbie
Have a book on PHP/MySQL. It deals with PHP 4 & MySQL 3.23. I have current versions of those programs. The book comes with a CD that has sample databases. I have copied the databases to \htdocs\book
The following script is supposed to open the databases (from .dump)
It does not. I do have Apache/MySQL/ PHP working together (from other resources)
<?
//script to install databases for php/mysql book
//to_install is the name of the database
//filename are in the form dbname.dump
mysql_connect("localhost", "root", "**Correct password*") or die
("<h3>Before Installing your Databases you must have MySQL installed and provide a valid host,
username, and password in line two of the install.dbs file.</h3>");
$all_dbs = array ("guestbook2k", "catalog", "discussion","netsloth", "survey", "tracking");
if(isset($submit))
{
$to_install = array();
if(isset($passed_dbs) && is_array($passed_dbs) && isset($install_all))
{
echo "Let's try this again. This time, please select the
databases you would like installed OR check Install All.
Not both. Press the back button, please.";
exit;
} elseif (isset($passed_dbs) && is_array($passed_dbs))
{
$to_install = $passed_dbs;
} elseif (isset($install_all))
{
$to_install = $all_dbs;
}
else
{
echo "Let's try this again. This time, please select the
databases you would like installed OR check Install All.
Press the back button, please.";
exit;
}
// $path = $DOCUMENT_ROOT . "/book/install/";
foreach($to_install as $dbname)
{
//create and slect database
mysql_query("drop database if exists $dbname") or die
(mysql_error() . "Could not drop database $dbname ");
mysql_query("create database $dbname") or die
(mysql_error() . "Could not create database $dbname ");
mysql_select_db($dbname);
//files will come in the form dbname.dump
//$file_to_parse = $path . $dbname . ".dump";
$file_to_parse = $dbname . ".dump";
if (!file_exists($file_to_parse))
{
echo "Could not find '$file_to_parse'. Are your files placed properly? Please check";
exit;
}
if (!$fp = fopen($file_to_parse, "r"))
{
echo "Read of $file_to_parse failed. Please check permissions.";
exit;
}
$contents = fread($fp, filesize ($file_to_parse));
fclose($fp);
//parse out drop, create, and insert statments
preg_match_all("/(DROP TABLE.?);/s", $contents, $drop_statements);
preg_match_all("/(CRE.?);/s", $contents, $create_statements);
preg_match_all("/(INSER.*?);[\n\r]/s", $contents, $insert_statements);
foreach($drop_statements[1] as $query)
{
mysql_query($query) or die
(mysql_error(). " drop table failed: $query.");
}
foreach($create_statements[1] as $query)
{
mysql_query($query) or die
(mysql_error(). " create table failed: $query.");
}
foreach($insert_statements[1] as $query)
{
mysql_query($query) or die
(mysql_error() . "insert failed: $query.");
}
echo "database \"$dbname\" successfully created.<br>\n";
}
}
else
{
?>
<h2>Welcome to the Applications for MySQL/PHP Applications Book</h2>
<p>If you are seeing this, you have PHP and MySQL installed and talking to each other. Cool</p>
<p>To get the applications working, you first need to install the databases with the sample data. Below
please choose the databases you would like installed. Choose the individual databases or mark Install
ALL.</p>
<p><b>NOTE: If you have databases by the same name on your MySQL server they will be
deleted! Beware.</b></p>
<p>Databases to install:book.dump</p>
<form action = <? echo $REQUEST_URI; ?> method="get">
<?
foreach($all_dbs as $dbname){
echo "<input type=\"checkbox\" name=\"passed_dbs[]\" value=\"$dbname\">$dbname<br>\n";
}
?>
<br>
<input type="checkbox" name="install_all" value="yes">Install All<br>
<input type="submit" name="submit" value="Submit">
</form>
<? } ?>
END OF SCRIPT
I do get the message :
Welcome to the Applications for MySQL/PHP Applications Book
If you are seeing this, you have PHP and MySQL installed and talking to each other. Cool
To get the applications working, you first need to install the databases with the sample data. Below please choose the databases you would like installed. Choose the individual databases or mark Install ALL.
NOTE: If you have databases by the same name on your MySQL server they will be deleted! Beware.
Then, no matter whether I try to install or a single database nothing happens.
My document root in the Apache config file is:
DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"
I do not know enough to solve the dilemna.
Any help would be appreciated
Brian
Navigate: Previous Message•Next Message
Options: Reply To This Message•Quote This