为什么出现致命错误:在非对象上调用成员函数prepare()? [英] Why i've Fatal error: Call to a member function prepare() on a non-object?
问题描述
我问了一个PDO错误问题( 因此,对于此行 致命错误:在...中的非对象上调用成员函数prepare()
可以帮我吗? 很明显,您的 如果未正确建立连接,则变量 现在,当您使用 现在,您应该在 I've ask a question for PDO error (here
But I've a another problem with object... Here is my code : Therefore I have this error for this line Fatal error: Call to a member function prepare() on a non-object in ... Can you help my, please ? It is all clear, Your When the connection is not established correctly, the variable Now, when you use Now, you should present a 这篇关于为什么出现致命错误:在非对象上调用成员函数prepare()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!$stmt = $bdd->prepare('SELECT COUNT(*) FROM utilisateurs WHERE identifiant = ?');
,我有此错误:$bdd
不包含SQL连接.您必须检查SQL连接的有效性.$bdd
必须是一个对象,因此它包含一个名为prepare()
的方法.$bdd
将不是对象,因此将没有方法prepare.$bdd->prepare()
时,它会引发错误,指出$bdd
不是对象,因此无法使用称为prepare()
$bdd->prepare()
行之前显示var_dump($bdd)
以便进行检查.include('../../config/connexion-bdd.php');
$nom = $_POST['nom'];
$regexNom = '/^[a-zA-Z -]+$/';
$prenom = $_POST['prenom'];
$regexPrenom = '/^[a-zA-Z -]+$/';
$email = $_POST['email'];
$regexEmail = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
$identifiant = $_POST['identifiant'];
$regexIdentifiant = '/^[a-z1-9]+$/';
$motDePasse = $_POST['motDePasse'];
$confirmeMotDePasse = $_POST['ConfirmeMotDePasse'];
$regexMdp = '/^[a-zA-Z1-9]+$/';
$utilisateurConnecte = $_POST['utilisateur-connecte'];
if (preg_match($regexNom, $nom) &&
preg_match($regexPrenom, $prenom) &&
preg_match($regexEmail, $email) &&
preg_match($regexIdentifiant, $identifiant) &&
preg_match($regexMdp, $motDePasse) &&
preg_match($regexMdp, $confirmeMotDePasse) &&
$motDePasse == $confirmeMotDePasse)
{
$stmt = $bdd->prepare('SELECT COUNT(*) FROM utilisateurs WHERE identifiant = ?');
$stmt->execute(array($_POST['identifiant']));
if ($stmt->fetchColumn() == 0){
$updt=$connect->prepare("INSERT INTO utilisateurs('nom','prenom','email','identifiant','mot_de_passe') VALUES (:nom, :prenom, :email, :identifiant, MD5(:mdp))");
$updt->execute(array('nom'=>$nom,'prenom'=>$prenom,'email'=>$email,'identifiant'=>$identifiant,'mdp'=>$motDePasse));
header('./gestion-utilisateur.php');
} else {
echo 'error 1';
}
} else {
echo 'error 2';
}
$stmt = $bdd->prepare('SELECT COUNT(*) FROM utilisateurs WHERE identifiant = ?');
:$bdd
is not containing a SQL connection. You have to check for the validity of the SQL connection.$bdd
must be an object, and thus it contains a method called prepare()
.$bdd
will not be an object and thus will not have a method prepare.$bdd->prepare()
it throws an error that $bdd
is not an object, thus it could not have a method called prepare()
var_dump($bdd)
before the $bdd->prepare()
line for use to inspect it.