Erreur de syntaxe: update set where
salut tous le monde,
L’erreur m’a perdu beaucoup de temps , svp Aide-moi pour le corriger
voila l'erreur :furieux:
Citation:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 Erreur de syntaxe près de 'WHERE id ='3'' à la ligne 5' in F:\Program Files\EasyPHP-5.3.3\www\1er-example\forum\class_UserTable.php:25 Stack trace: #0 F:\Program Files\EasyPHP-5.3.3\www\1er-example\forum\class_UserTable.php(25): PDOStatement->execute(Array) #1 F:\Program Files\EasyPHP-5.3.3\www\1er-example\forum\main.php(9): UserTable->update('adel', 'g', 3) #2 {main} thrown in F:\Program Files\EasyPHP-5.3.3\www\1er-example\forum\class_UserTable.php on line 25
table étuliser etudiant (nom,sex ,id)
contenu de fichier "class_UserTable.php"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
class UserTable
{
private $update;
public function __construct($db)
{
$this->update = $db->prepare(
"UPDATE etudiant
SET
nom = :nom,
sex = :sex,
WHERE id =:id");
}
public function update($nom, $sex, $id)
{
$this->update->execute(
/*ligne 25*/ array(':nom' => $nom,':sex'=>$sex,'id'=> $id));/*ligne 25*/
return $this->update->rowCount();
}
} |
contenu de fichier "class_MyPDO.php"
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <?php
class MyPDO extends PDO
{
public function __construct($dsn, $user=NULL, $password=NULL)
{
parent::__construct($dsn, $user, $password);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
public function prepare($sql, $options=NULL)
{
$statement = parent::prepare($sql);
if(strpos(strtoupper($sql), 'SELECT') === 0) //requête "SELECT"
{
$statement->setFetchMode(PDO::FETCH_ASSOC);
}
return $statement;
}
}
?> |
contenu de fichier "main.php"
Code:
1 2 3 4 5 6 7 8 9 10
| <?php
require_once 'class_UserTable.php';
require_once 'class_MyPDO.php';
$db = new MyPDO('mysql:host=localhost;dbname=all', 'root', '');
$userTable = new UserTable($db);
/*ligne 9*/echo"le nombre de lignes modifier=".$userTable->update('adel','g',3);
?> |