09-23-2007, 04:11 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Installing..
Hey, I got a problem again >.<
PHP Code:
include('core/database.php');
$step = $_GET['step'];
?>
<div class="page">
<div id="pagetitle">
<h1>Installing...</h1>
<hr>
</div>
<div id="pagestep">
<?php
switch($step) {
case 1:
if(!isset($_POST['connect'])) {
?>
<p>Step 1: Database connection</p>
</div>
<div id="pageform">
<form action="<?php $_SERVER['PHPSELF']; ?>" method="POST">
<div id="pagecat2">Database host:</div>
<input type="text" name="host" value="localhost">
<div id="pagecat2">Database user:</div>
<input type="text" name="user" value="root">
<div id="pagecat2">Database password:</div>
<input type="text" name="pass">
<div id="pagecat2">Database name:</div>
<input type="text" name="data">
<input type="submit" value="Connect" name="connect">
</form></div>
<?php
} elseif(isset($_POST['connect'])) {
$user = $_POST['user'];
$host = $_POST['host'];
$pass = $_POST['pass'];
$data = $_POST['data'];
$test = new database($host, $user, $pass, $data);
if(!$test) {
?>
<p>Step 1: Database connection</p>
<div id="pagecat2">Failed! Check your database again for the correct data.</div>
<a href="install.php?step=1">Go back</a>
<?php
}
else {
?>
<p>Step 1: Database connection</p>
<div id="pagecat2">Success! Please click the link in order to proceed.</div>
<a href="install.php?step=2">Step 2</a>
<?php
$file = 'config.php';
$open = fopen($file, 'a');
$content =
'<?php
function __autoload($class_name) {
require_once \'core/\' . $class_name . \'.php\';
}
$system->db = new database(\''.$host.'\', \''.$user.'\', \''.$pass.'\', \''.$data.'\');';
$write = fwrite($open, $content);
fclose($open);
}
}
}
Basicly, it's this line:
PHP Code:
$test = new database($host, $user, $pass, $data);
if(!$test) {
What I'm trying to do here is that if the database connection attempt is not successful, then it should do the things inside the brackets of the if(!$test) { }
Database class is like this:
PHP Code:
public function __construct($host, $user, $pass, $db) {
$this->db['host'] = $host;
$this->db['user'] = $user;
$this->db['pass'] = $pass;
$this->db['db'] = $db;
$this->connect();
}
private function connect() {
$connect = @mysql_connect($this->db['host'], $this->db['user'], $this->db['pass']);
if(!$connect) {
return false;
}
else {
$this->select();
}
}
private function select() {
$select = @mysql_select_db($this->db['db']);
if(!$select) {
return false;
}
else {
return true;
}
}
|
|
|
|