Location: PHPKode > scripts > PHPhotoalbum > phphotoalbum/dbinit.php
<?
/*************************************************
 * PHPhotoalbum v0.5
 * by: Henning Støverud
 * e-mail: hide@address.com
 * URL: http://www.stoverud.com/PHPhotoalbum/
 *************************************************/

 

 
 
session_start(); 

include("config.inc.php");
include("functions.php");

if($_POST['action'] == "dbinit")
{ 
	$albums = "CREATE TABLE album_albums (
	  aid mediumint(10) NOT NULL auto_increment,
	  description text NOT NULL,
	  uploads enum('YES','NO') NOT NULL default 'YES',
	  date datetime default NULL,
	  PRIMARY KEY  (aid),
	  KEY aid (aid)
	) TYPE=MyISAM;";

	$comments = "CREATE TABLE album_comments (
	  pid varchar(10) NOT NULL default '',
	  msg_id mediumint(10) NOT NULL auto_increment,
	  userhost varchar(200) NOT NULL default '',
	  msg_subject varchar(200) NOT NULL default '',
	  msg_body text NOT NULL,
	  msg_date datetime default NULL,
	  PRIMARY KEY  (msg_id)
	) TYPE=MyISAM;";
	
	$pictures = "CREATE TABLE album_pictures (
	  pid mediumint(10) NOT NULL auto_increment,
	  aid varchar(10) NOT NULL default '',
	  filepath varchar(200) NOT NULL default '',
	  filename varchar(200) NOT NULL default '',
	  filesize int(25) NOT NULL default '0',
	  pwidth varchar(5) NOT NULL default '',
	  pheight varchar(5) NOT NULL default '',
	  hits mediumint(10) NOT NULL default '0',
	  PRIMARY KEY  (pid)
	) TYPE=MyISAM;";

	echo "Response from MySQL server:<br>";
	$conn = mysql_connect($_POST['dbserver'],$_POST['dbuser'],$_POST['dbpass']);
	if(!$conn) {
		echo mysql_error();
	}
	
	$db = mysql_select_db($_POST['dbname']);
	if(!$db) {
		echo mysql_error()."<br>";
	}
	$q1 = mysql_query($albums);
	if(!$q1){
		echo mysql_error()."<br>";
	}
	$q2 = mysql_query($comments);
	if(!$q2)
		echo mysql_error()."<br>";
	$q3 = mysql_query($pictures);
	if(!$q1)
		echo mysql_error()."<br>";
	if($conn && $db && $q1 && $q2 && $q3)
	{
		echo "Database initialization OK...";
	}
}



pageheader("DBinit"); ?>

<? navmenu(450); ?>
<!-- 1px BORDER -->
<table width="450" align="center">
 <td bgcolor="#000000">
<!-- 1px BORDER -->

<!-- MAIN TABLE -->
	<table bgcolor="<? echo $config['color_main']; ?>" width="448">
	  <tr>
		<td>
<!-- MAIN TABLE SECTION -->

<table width="100%" cellspacing=10>
	<div style="thumbnails" align="right"><h3>DB init<hr></h3></div>
	
	
	
	<p>
	
<?php
$result = mysql_list_tables($dbname);
$counter = 0;
if($result)
{
	while ($row = mysql_fetch_row($result)) {
	   if($row[0] == "album_albums") {
	   	echo "album_albums OK<br>";
	    $counter++;
	   }
	   if($row[0] == "album_pictures") {
	   	echo "album_pictures OK<br>";
	   	$counter++;
	   }
	   if($row[0] == "album_comments") {
	   	echo "album_comments OK<br>";
	    $counter++;
	   }
	}
}

if($counter == 3)
{
	echo "<br>Your database is setup and ready for use.<br>";
	echo "Please make sure the database settings in your config.inc.php looks like this:<br>";

?>
<br>
<div style="background: #ececec; font-size:10px;">
// DATABASE SETTINGS<br>
$config['dbserver'] = "<?=$_POST[dbserver];?>";<br>
$config['dbuser'] = "<?=$_POST[dbuser];?>";	<br>
$config['dbpass'] = "<?=$_POST[dbpass];?>";	<br>
$config['dbname'] = "<?=$_POST[dbname];?>"; <br>
<br>
$config['TABLE_PICTURES'] = "album_pictures";<br>
$config['TABLE_ALBUMS'] = "album_albums";	<br>
$config['TABLE_COMMENTS'] = "album_comments";<br>
</div>

<br>
<br>
More installation instructions <a href="installation.php">here &gt;&gt;</a>
<?
return;
} // End if($counter == 3)
?>


	
	
	<p>
	<form action="" method="post">
	<input type="hidden" name="action" value="dbinit">
	<table>
       <tr>
        <td colspan="2"><b>Your MySQL configuration</b>
        </td>
       </tr>
       <tr>
        <td  colspan="2"> This section requires information on how to access your MySQL database. If you don't know how to fill them, check with your webhost support.
        </td>
       </tr>
       <tr>
        <td width="40%"><b>MySQL Host</b><br />(localhost is usually OK)
        </td>
        <td width="60%" valign="top">
                <input type='text' name='dbserver' value='<?php echo ($HTTP_POST_VARS['dbserver'] ? $HTTP_POST_VARS['dbserver'] : 'localhost') ?>'>
        </td>
       </tr>
       <tr>
        <td width="40%"><b>MySQL Database Name</b>
        </td>
        <td width="60%">
                <input type='text' name='dbname' value='<?php echo $HTTP_POST_VARS['dbname'] ?>'>
        </td>
       </tr>
       <tr>
        <td width="40%"><b>MySQL Username</b>
        </td>
        <td width="60%">
                <input type='text' name='dbuser' value='<?php echo $HTTP_POST_VARS['dbuser'] ?>'>
        </td>
       </tr>
       <tr>
        <td width="40%"><b>MySQL Password</b>
        </td>
        <td width="60%">
                <input type='text' name='dbpass' value='<?php echo $HTTP_POST_VARS['dbpass'] ?>'>
        </td>
       </tr>
	   <tr>
	   	<td>
		</td>
		<td>
			<input type='submit' value='Go!'>
		</td>
	  </tr>
		</form>
	</table>		


	</div>



</table>


	</td>
  </tr>
</table>


	
<!-- /MAIN TABLE SECTION -->
		</td>
      </tr>
	</table>
<!-- /MAIN TABLE SECTION -->


<!-- /1px BORDER -->
 </td>
</table>
<!-- /1px BORDER -->

<? pagefooter(450); ?>
Return current item: PHPhotoalbum