Citaat van Dpm_x@BrokenTrack , laat eens wat van jouw code zien?
PHP
<?php
###########################
### Copyright SimplePHP ###
### Created by ###
### BrokenTrack.com ###
### Author: ###
### Tim van den Belt ###
### Licensed under: ###
### {input_licence_here ###
###########################
/*
@author Tim van den Belt
*/
class Mysql extends SimplePHP {
private $connection;
private $connected = false;
/*
This will connect with the mysql database and selects the right database.
On fail an exception will be caught and printed. This will set the core initialisation on false.
*/
public function check_connection() {
if(!$this->Database->connected) {
try {
$this->Connection = $this->connect();
$this->select_db();
return true;
}
catch(Exception $e) {
$e->add_error('<strong>SimplePHP error:</strong> Mysql error in '.$e->getFile().' on line '.$e->getLine().' because: '.$e->getMessage().'<br />');
$this->core_load_false();
return false;
}
}
}
/*
Tries to connect with the mysql server. Exception on error.
*/
private final function connect() {
if(!$this->Database->Connection = @mysql_connect(SERVER,DATABASE_USER,DATABASE_PASSWORD)) {
throw new Exception('Cannot connect with the mysql server');
return false;
}
$this->Database->connected = true;
return true;
}
/*
Tries to select the database. Exception on error.
*/
private final function select_db() {
if(!@mysql_select_db(DATABASE)) {
throw new Exception('Cannot select the database');
return false;
}
return true;
}
/*
@param, the query string that needs to be executed.
@return, the result of the query.
Will try to execute the query. Will use the Error Exception class on error.
*/
public function query($query) {
try {
$result = $this->Mysql->do_query($query);
}
catch(Error $e) {
$e->add_error('SQL query error in '.$e->getFile().' on line '.$e->getLine.' because: '.$e->getMessage());
return false;
}
return $result;
}
/*
@param, the query that needs to be executed
@return, the result of the query
Will execute the query, exception on error
*/
private final function do_query($query) {
if(!$result = @mysql_query($query)) {
throw new Exception(mysql_error());
return false;
}
return $result;
}
/*
@param, the query string that needs to be assoced.
@return, the result of the query.
Will try to assoc the query. Will use the Error Exception class on error.
*/
public final function assoc($query) {
$query = $this->Mysql->query($query);
try {
$result = $this->Mysql->do_assoc($query);
}
catch(Error $e) {
$e->add_error('SQL assoc error in '.$e->getFile().' on line '.$e->getLine.' because: '.$e->getMessage());
return false;
}
return $result;
}
/*
@param, the query that needs to be assoced
@return, the result of the assoc
Will assoc the query, exception on error
*/
private final function do_assoc($query) {
if(!$result = @mysql_fetch_assoc($query)) {
throw new Exception(mysql_error());
return false;
}
return $result;
}
/*
Closes the mysql connection if any
*/
protected final function close() {
if($this->Database->connection) {
if($this->Database->Connection) {
@mysql_close($this->Database->$connection);
return false;
}
}
return true;
}
}
?>
Toon Meer
Stukje van het framework waar ik mee bezig ben. Deze klasse is waarschijnlijk nog niet af.