Ho scritto questa classe per inziare a programmare ad oggetti
in PHP e sto trovando un pò di difficoltà volevo capire perché mi dice
che la query che eseguo é vuota almeno stando a quello che
dice il messagio di errore di Mysql:
Impossibile eseguire query al database
Dettagli: Query was empty
Errore No: 1065
Il codice é questo:
<?php
//db_class.php
error_reporting(E_ALL);
class Db_Connect {
var $host;
var $user;
var $pasw;
function make_connect($host, $user, $pasw) {
$this->host = $host;
$this->user = $user;
$this->pasw = $pasw;
$link_id = mysql_connect($this->host, $this->user, $this->pasw);
if (!$link_id) {
die("Impossibile connettersi al server mysql " . "
" .
"Dettagli: " . mysql_error() . "
" . "Errore No: " . mysql_errno());
}
else {
return $link_id;
}
}
function select_db($db_name) {
if (!(mysql_select_db($db_name))) {
die("Impossibile selezionare il database " . $db_name . "
" .
"Dettagli: " . mysql_error() . "
" . "Errore No: " . mysql_errno());
}
}
function sql_query($query) {
global $query;
$query = $query;
if (!(mysql_query($query))) {
die("Impossibile eseguire query al database " . "
" .
"Dettagli: " . mysql_error() . "
" . "Errore No: " . mysql_errno());
}
else $result = mysql_query($query);
return $result;
}
function get_id_result() {
return $this->sql_query($query);
}
function close_connection() {
mysql_close($this->make_connect());
}
}
class Result_Db extends Db_Connect {
function get_data() {
$res = $this->get_id_result();
while($db_data = mysql_fetch_array($res)) {
echo $db_data["id"] . "
";
}
}
}
$obj = new Result_Db;
$obj->make_connect('localhost', 'root', '');
$obj->select_db('mio DB');
$obj->sql_query('select id from tabella1');
$obj->get_data();
?>
Geazie a tutti in anticipo