Compatibilité PHP 5.2 / 5.3 ?
Posté : 04 avr. 2012, 20:05
Bonjour à tous,
Je suis tombé sur un problème bizzare.
Ma classe :
Fatal error: Call to a member function query() on a non-object in /home/programming/class.php on line 51
La ligne 51 :
Du coup j'aimerais bien une confirmation ? est ce impossible a faire sur PHP 5.2 ? et pourquoi cette erreur dessus ?
Merci d'avance a celui qui pourrais m'éclairer.
Je suis tombé sur un problème bizzare.
Ma classe :
class ManageDB
{
private $bdd;
private db_table;
public function __construct ($pdo_host, $pdo_user, $pdo_password, $pdo_bdd, $pdo_table)
{
$this->db_table = $pdo_table;
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$this->bdd = new PDO('mysql:host=' . $pdo_host . ';dbname=' . $pdo_bdd, $pdo_user, $pdo_password, $pdo_options);
}
public function getUser($id)
{
$req = $this->bdd->query('SELECT user FROM '.$this->db_table.' WHERE id=\''.$id.'\' LIMIT 0, 1');
while ($str = $req->fetch())
{
$getUser = $str['user'];
}
$req->closeCursor();
return $getUser ;
}
Mon script file.php
require("maclass.php");
$user = new ManageDB('localhost', 'root', '', 'mabdd', 'matable');
echo $user->getUser("5");
Résultat obtenue :Fatal error: Call to a member function query() on a non-object in /home/programming/class.php on line 51
La ligne 51 :
$req = $this->bdd->query('SELECT user FROM '.$this->db_table.' WHERE id=\''.$id.'\' LIMIT 0, 1');
Le truc bizzare c'est que lors du teste j'utilisais la version 5.2 de PHP, puis j'ai eu l'idée du siècle.. tester sous PHP 5.3 ! et la miracle sa marche ! Du coup j'aimerais bien une confirmation ? est ce impossible a faire sur PHP 5.2 ? et pourquoi cette erreur dessus ?
Merci d'avance a celui qui pourrais m'éclairer.