Olen suht aloittelija php ohjelmoinnissa, täysi noobi class jutuissa. Ongelmani on että koodi valittaa "Fatal error: Call to undefined function mysql_log_error() in C:\xampp\htdocs\mysql\mysql.php on line 55" vaikka mysql_log_error löytyy tuosta koodista???
<?php
class mysql{
var $mysql;
var $err;
function define_settings() {
/*
Username, password, host and database information.
If you want use more than one database, this will be primary.
Change used database with function mysql_change_db
*/
$this -> mysql['user'] = 'root';
$this -> mysql['pass'] = 'tarhak';
$this -> mysql['host'] = 'localhost';
$this -> mysql['database'] = 'simloads';
$this -> err['con'] = 'Tietokantaan ei voitu yhdistää.';
$this -> err['select_db'] = 'Virhe havaittu tietokantannan käytössä';
$this -> err['gen'] = 'Virhe havaittu, sivua ei voida valitettavasti näyttää';
$this -> err['logfile'] = 'mysql_errors.log';
}
function mysql_do_connect() {
$this->define_settings();
$mysql_connection = mysql_pconnect($this->mysql['host'], $this->mysql['user'], $this->mysql['pass']);
$mysql_database = mysql_select_db($this->mysql['database']);
if (!$mysql_connection) {
$sql_return = mysql_error();
mysql_log_error('con', $sql_return);
} elseif (!$mysql_database) {
$sql_return = mysql_error();
mysql_log_error('select_db', $sql_return);
}
}
function mysql_log_error($errormsg, $sql_return) {
$this -> define_settings();
//Error to log
$handle = fopen($this->err['logfile'], 'a');
$msg = $_SERVER['remote_addr'].' @ '.date("[d-m-Y H:i:s] ").': '.$sql_return;
fwrite($handle, $msg);
fclose($handle);
//output for user
error('CRITICAL_ERROR', 'Kriittinen mysql-virhe', $this -> err[$errormsg]); //tämä on erillinen functio joka tulostaa annetun virheen hienosti käyttäjälle. Hoitaa myös exitin, jos tarvitaan.
}
function run_mysql_query($query) {
$query_result = mysql_query($query);
if (!$query_result) {
$sql_return = mysql_error();
mysql_log_error('gen', $sql_return); //Tätä se valittaa
} else {
return($query_result);
}
}
}
?>mysql_log_error() => $this->mysql_log_error()
Ok kiitos.
Aihe on jo aika vanha, joten et voi enää vastata siihen.