Salve ho una classe connessione che sto costruendo :
Richiamando in una pagina esterna il metodo eseguiqueryfetch($sql)codice:<?php include '../config/config.php'; /** * */ class Connessione { /** * @var object $db_connection The database connection */ private $db_connection = null; function __construct(){ session_start(); $this->databaseConnection(); } /** * Checks if database connection is opened and open it if not */ private function databaseConnection() { // connection already opened if ($this->db_connection != null) { return true; } else { // create a database connection, using the constants from config/config.php try { // Generate a database connection, using the PDO connector // @see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/ // Also important: We include the charset, as leaving it out seems to be a security issue: // @see http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers#Connecting_to_MySQL says: // "Adding the charset to the DSN is very important for security reasons, // most examples you'll see around leave it out. MAKE SURE TO INCLUDE THE CHARSET!" $this->db_connection = new PDO('mysql:host='. DB_HOST .';dbname='. DB_NAME . ';charset=utf8', DB_USER, DB_PASS); return true; // If an error is catched, database connection failed } catch (PDOException $e) { $this->errors[] = MESSAGE_DATABASE_ERROR; return false; } } } public function get_databaseConnection(){ return $this->db_connection; } public function eseguiqueryfetch($sql){ if($this->get_databaseConnection()){ //Eseguo la query $statement = $this->get_databaseConnection()->query($sql); $result = $statement->fetch(PDO::FETCH_ASSOC); return $result; } else{ echo'errore'; } } public function contaRighe($sql){ $connessione=$this->get_databaseConnection(); //Preparo la query $query = $connessione->prepare($sql); //eseguo la query $query->execute(); //conto le righe $count = $query->rowCount(); return $count; } } ?>
ho il seguente errore , premetto che la connessione è presente e che la stringa sql inserita in php admin funziona....
Quale è l'errore
Call to a member function fetch() on a non-object in /membri/my_site/classes/Connessione.php on line 65

Rispondi quotando
