Location: PHPKode > projects > phpBible > phpbible/install/populate_db.php
<?php


reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) 
  {
  $$key=$value;
  }

reset ($HTTP_GET_VARS);
while (list ($key, $val) = each ($HTTP_GET_VARS)) 
  {
  $$key=$value;
  }

echo "<html>

<head>
<title>phpBible.org</title>
<link rel=\"stylesheet\" type=\"text/css\" href=\"../phpBible.css\">
</head>

<body class=\"light\"><center>

<b><font color=\"$page_dark\" size=\"7\" face=\"Georgia\">phpBible.org<br>
</font><font color=\"$page_dark\" face=\"Georgia\" size=\"4\">Online Study Bible</font></b><br>
<font color=\"$page_dark\"><b><font face=\"Verdana\" size=\"3\">Installation: Step 2</font></b><br>

";


require("../config.php");
$link = mysql_connect($host, $user, $password)
    or die("Could not connect : " . mysql_error());

$db_list = mysql_list_dbs($link);

$i = 0;
$cnt = mysql_num_rows($db_list);
while ($i < $cnt)
  {
  $temp=mysql_db_name($db_list, $i);
  $names.="%%%$temp%%%";
#  if($temp==$db_name){$db_found='yes';}
  $i++;
  }
if(!strstr($names, $db_name))
#if(!$db_found)
  {
  if (mysql_create_db($db_name))
    {
    echo "Database '$db_name' created successfully<br>\n";
    }
  else
    {
    echo "Error creating database: " . mysql_error() . "\n";
    }
  }

mysql_select_db($db_name) or die("Could not select database");
$av_text=file("./phpBible_av.dat");

$table_name=$table_prefix;
$table_name.='av';

$query = "DROP TABLE IF EXISTS $table_name;";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

$query = "CREATE TABLE $table_name (row int(2), book int(2), chapter int(3), verse int(3), text text, coding text);";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
echo "Table '$table_name' created.<br>\n";

for($i=0;$i<=31101;$i++)
  {
  $row=$i+1;
  $temp=$av_text[$i];
  $temp=str_replace("\n", '', $temp);
  $temp=str_replace("\r", '', $temp);
  $temp=str_replace('INTO av VALUES (', "INTO $table_name VALUES (", $temp);
  if($temp){$result = mysql_query($temp) or die("Query failed ($i) : " . mysql_error());}
  }
echo "Table '$table_name' populated.<br>\n";

$table_name=$table_prefix;
$table_name.='books';

$query = "DROP TABLE IF EXISTS $table_name;";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

$query = "CREATE TABLE $table_name (number int(2) DEFAULT '0' NOT NULL, book char(20) NOT NULL, chapters int(3), abbr text, PRIMARY KEY (number));";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
echo "Table '$table_name' created.<br>\n";

for($i=31103;$i<=31168;$i++)
  {
  $temp=$av_text[$i];
  $temp=str_replace("\n", '', $temp);
  $temp=str_replace("\r", '', $temp);
  $temp=str_replace('INTO books VALUES', "INTO $table_name VALUES", $temp);
  if($temp){$result = mysql_query($temp) or die("Query failed ($i) : " . mysql_error());}
  }
echo "Table '$table_name' populated.<br>\n";
#mysql_free_result($result);
echo "

<p align=\"center\"><a href=\"populate_db2.php\">Click to continue...</a></p>
</center>
</body>

</html>";
?> 
Return current item: phpBible