MySQL

Transcription

MySQL
MySQL
●
Stockage des informations
●
Langage SQL
MySQL
●
●
●
●
●
●
//CREATE TABLE Table1 SELECT Champ1,Champ2 FROM Table1 [WHERE Champ1 = '….']
INSERT INTO Table1 (Champ1,Champ2) VALUES ('val1','val2'); DELETE FROM Table1 WHERE …
UPDATE Table1 SET Champ1 = … WHERE Champ2 = ….
//DROP TABLE Table1
MySQL
●
Via PhpMyAdmin, créer une table ”billet” dans une database ”blog”
●
Id (int auto_increment)
●
Sujet(varchar 255)
●
Contenu(text)
●
Date (DATETIME '0000­00­00 00:00:00')
●
Et entrer un contenu sujet + contenu
PHP - MySQL
●
Utilisation de l'extension PDO
●
Ouverture d'une connexion vers serveur MySQL
try
{
$conn = new PDO('mysql:host=localhost;dbname=test', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e­>getMessage());
}
$reponse = $conn­>query('SELECT Champ1,Champ2 FROM Table1 ');
// Affichage de chaque message (toutes les données sont protégées par htmlspecialchars)
while ($donnees = $reponse­>fetch())
{
echo htmlspecialchars($donnees['Champ1']) . ' : ' . htmlspecialchars($donnees['Champ2']) . '<br>';
}
$reponse­>closeCursor();
PHP - MySQL
●
Exercice
●
Créer une page qui affiche le contenu de la table créée via phpmyadmin
PHP - MySQL
●
Insertion
$conn­>prepare('INSERT INTO Table1 (Champ1, Champ2) VALUES(?, ?)');
$req­>execute(array($varChamp1, $varChamp2));
PHP - MySQL
●
Exercice ●
Associer au formulaire créé, la page enregistrant une nouvelle entrée dans la table billet

Documents pareils