Pour Connecter La Base de Données Avec PHP
Pour Connecter La Base de Données Avec PHP
Pour Connecter La Base de Données Avec PHP
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
Méthode1 :
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
$sql->execute();
Méthode2:
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
$sql->execute();
Formulaire accorder avec base de données:
<body>
<?php
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
$title = $_POST["title"];
$content = $_POST["content"];
$date = $_POST["date"];
$time = $_POST["time"];
}
?>
<form method="post">
title: <input type="text" name="title" required><br>
content: <input type="text" name="content" required><br>
date: <input type="date" name="date" required><br>
time: <input type="time" name="time" required ><br>
<button type="submit" name="send">ajouter</button>
</form>
</body>
</html>
Pour savoir le nombre de ligne dans la base de donnée :
<?php
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
// -> tazwidiha prepare , execute = objects
$sql=$database->prepare("SELECT * FROM articles");
$sql->execute();
echo $sql->rowCount();
?>
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
// -> tazwidiha prepare , execute = objects
$sql=$database->prepare("SELECT * FROM articles");
$sql->execute();
echo $sql->columnCount();
?>
Faire formulaire accorder avec la base de données d’une façon sécurisés :
<body>
<?php
$username="root";
$password= "";
$database = new PDO ("mysql:host=localhost;dbname=codershiyar;charset=utf8;",
$username,$password);
$title = $_POST["title"];
$content = $_POST["content"];
$date = $_POST["date"];
$time = $_POST["time"];
$sql->bindParam("title",$title);
$sql->bindParam("content",$content);
$sql->bindParam("date",$date);
$sql->bindParam("time",$time);
$sql->execute();
if($sql->execute()){
echo"vous avez ajouter avec succès !!!!!";
}else{
echo"vous n'avez pas ajouter avec succès !!!!!";
}
?>
<form method="post">
title: <input type="text" name="title" required><br>
content: <input type="text" name="content" required><br>
date: <input type="date" name="date" required><br>
time: <input type="time" name="time" required ><br>
<button type="submit" name="send">ajouter</button>
</form>
</body>