Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database extends Debug
- {
- /**
- * MYSQL server.
- *
- * @access private
- * @var string $server
- */
- private $server;
- /**
- * MSQL login name.
- *
- * @access private
- * @var string $login
- */
- private $login;
- /**
- * MYSQL login password.
- *
- * @access private
- * @var string $password
- */
- private $password;
- /**
- * MYSQL database.
- *
- * @access private
- * @var string $database
- */
- private $database;
- /**
- * Constructor.
- *
- * @access public
- * @param string $server mysql server
- * @param string $login mysql loginname
- * @param string $password mysql password
- * @param string $database mysql database
- */
- public function __construct ($server, $login, $password, $database)
- {
- $id = "__construct";
- $this->debug($id, "input $server");
- $this->debug($id, "input $login");
- $this->debug($id, "input $password");
- $this->debug($id, "input $database");
- $this->server = $server;
- $this->login = $login;
- $this->password = $password;
- $this->database = $database;
- parent::__construct("Database");
- }
- /**
- * Connect to mysql server and database.
- *
- * @access public
- */
- public function connect ()
- {
- $handle = mysql_connect($this->server
- , $this->login
- , $this->password)
- or die("Could not connect to $login@$host ". mysql_error());
- if ( !$handle )
- {
- throw new DatabaseException("Can not connect to database");
- }
- $dbSelected = mysql_select_db($this->database)
- or die("Could not select database $database " . mysql_error());
- if ( !dbSelect )
- {
- throw new DatabaseException("Could not select database $database");
- }
- }
- /**
- * Execute sql query.
- *
- * @access public
- * @param string $sql sql query
- * @return boolean true if there is no error
- */
- public function execute ($sql)
- {
- $id = "execute";
- $this->debug($id, "input $sql");
- $resource = mysql_query($sql);
- if ( !$resource )
- {
- throw new DatabaseException("Can't execute $sql");
- }
- $this->debug($id, "[output: $resource]");
- return $resource;
- }
- /**
- * Close mysql connection.
- *
- * @access public
- */
- public function close ()
- {
- mysql_close();
- }
- }
- // End of file
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement