Location: PHPKode > projects > phpBandwidth > phpbandwidth/db_install.php
<?php
require "db_config.php";
require "db_$db[type].php";
$conn = db_connect();
if ($conn === FALSE)
{	// Bitch about the connection
	?>
	I could not connect to you database<br>
	I am trying with these parameters:<br>
	Database host: '<?=$db[host]?>'<br>
	Database name: '<?=$db[name]?>'<br>
	Database user: '<?=$db[user]?>'<br>
	Database password: yeah, i would put that here ;)<br>
	<br>
	These parameters is edited in the db_config.php file in the base dir<br>
	Have you created the database?<br>
	<form action="<?=$PHP_SELF?>" method="post">
	<input type="submit" value="Retry">
	</form><?
}
else if(empty($create_the_db)) {
?>
phpBandwidth database initialisation.<br>
<br>
<font color="green">I am connected to you database and i am ready to create the tables...</font>
<br>
Do you want to create the tables in database: '<?=$db[name]?>'
<form action="<?=$PHP_SELF?>" method="post">
<input type="hidden" name="create_the_db" value="yes">
<input type="submit" value="Start">
</form>
<?
} else {
$messages = "Install status<br><tt>";
if ($db[type] == "postgresql")
	{
	$users_query = "CREATE TABLE $db[users]
	(
	    uid serial NOT NULL,
	    name character varying(50) NOT NULL,
	    \"limit\" integer NOT NULL,
	    iptables_name character varying(20)
	);";
	$routes_query = "CREATE TABLE $db[routes]
	(
	    uid integer NOT NULL,
	    \"table\" character varying(20) NOT NULL,
	    \"chain\" character varying(20) NOT NULL,
	    route_nr smallint NOT NULL,
	    \"in\" boolean NOT NULL
	);";
	$bw_data_query = "CREATE TABLE $db[bw_data]
	(
	    uid integer NOT NULL,
	    counter int8 NOT NULL,
	    \"in\" boolean NOT NULL,
	    date_of_record timestamp without time zone DEFAULT now() NOT NULL
	);";
}
else
{
	print "Sorry database type '$db[type]' not inplemented yet, in db_install.php";
	exit;
}
if(db_query($conn, $users_query))
	$messages .= "<font color=\"green\">User List Created</font><br>";
else{
	$messages .= "<font color=\"red\">User List Failed</font><br>";
	$error = true;
}
if(db_query($conn, $routes_query))
	$messages .= "<font color=\"green\">Routes Table Created<br>";
else {
	$messages .= "<font color=\"red\">Routes Table Failed</font><br>";
	$error = true;
}
if(db_query($conn, $bw_data_query)) 
	$messages .= "<font color=\"green\">Bandwidth data Table Created</font><br>";
else {
	$messages .= "<font color=\"red\">Bandwidth data Table Failed</font><br>";
	$error = true;
}
$messages .= "</tt>";
print $messages;
if (!$error){
?>
<br>
<font color="green" size="+2">Everything ok!</font><br>
Now you can continue in the INSTALL textfile<br>
<?}
}
?>
Return current item: phpBandwidth