I am posting the MySQL wrapper class I started:
Code: Select all
//wrapper class
class MySQL_Wrapper {
private $db = null;
private $dbname = null;
public function __construct($dbname, $dbhost, $dbuser, $dbpass){
$this->db = mysql_pconnect($dbhost, $dbuser, $dbpass);
if(!$this->db){
throw new RuntimeException("Error: Could not connect to database. Please try again later.");
} else $this->dbname = $dbname;
}
public function db_create(){
$sql = 'CREATE DATABASE '.$this->dbname;
if (mysql_query($sql, $this->db)) {
echo "Database {$this->dbname} created successfully\n";
return true;
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
return false;
}
}
public function db_delete(){
$sql = 'DROP DATABASE '.$this->dbname;
if (mysql_query($sql, $this->db)) {
echo "Database {$this->dbname} deleted successfully\n";
return true;
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
return false;
}
}
public function db_close(){
return mysql_close($this->db);
}
}
//php code which is giving me problem, or is it the class how it is defined
try{
$sql = new MySQL_Wrapper("UDatabase", "localhost", "root", "123456789mysql");
if($sql->db_create()){
Echo "Now you want to enter information\n";
}
if($sql->db_delete()){
Echo "database was deleted!";
}
$sql->db_close();
} catch(RuntimeException $e){
die($e->getMessage());
}
But I get these error messages:
Code: Select all
[27-Nov-2014 09:02:10 America/New_York] PHP Warning: Missing argument 1 for MySQL_Wrapper::__construct(), called in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 133 and defined in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 6
[27-Nov-2014 09:02:10 America/New_York] PHP Warning: Missing argument 2 for MySQL_Wrapper::__construct(), called in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 133 and defined in F:\Eclipse\Eclipse_Projects\PHP_ChessEditor\Server\Console\server.php on line 6
[27-Nov-2014 09:02:10 America/New_York] PHP Warning: Missing argument 3 for MySQL_Wrapper::__construct(), called in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 133 and defined in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 6
[27-Nov-2014 09:02:10 America/New_York] PHP Warning: Missing argument 4 for MySQL_Wrapper::__construct(), called in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 133 and defined in F:\Eclipse\Eclipse_Projects\PHP_ChessEditor\Server\Console\server.php on line 6
[27-Nov-2014 09:02:10 America/New_York] PHP Notice: Undefined variable: dbhost in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 7
[27-Nov-2014 09:02:10 America/New_York] PHP Notice: Undefined variable: dbuser in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 7
[27-Nov-2014 09:02:10 America/New_York] PHP Notice: Undefined variable: dbpass in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 7
[27-Nov-2014 09:02:10 America/New_York] PHP Warning: mysql_pconnect(): Access denied for user ''@'localhost' (using password: NO) in F:\Eclipse\Eclipse_Projects\PHP_ChessEditor\Server\Console\server.php on line 7
[27-Nov-2014 09:02:10 America/New_York] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Error: Could not connect to database. Please try again later.' in F:\Eclipse\PHP_Project1\Server\Console\server.php:9
Stack trace:
#0 F:\Eclipse\PHP_Project1\Server\Console\server.php(133): MySQL_Wrapper->__construct()
#1 {main}
thrown in F:\Eclipse\PHP_Project1\Server\Console\server.php on line 9
UPDATE: I was looking at my MySQL phpinfo() settings, and it missing the MySQL.default_host, user, password, etc. should I edit that into the php.ini file or is that supposed to stay that way?