Source : lesson_14_e0_writing_in_mysql.php |
Résultat |
<?php require ("../mysql_connexion/mysql_connexion.php"); require ("../commons/functions.php"); //mysql_select_db($db) ; $tableName = "atelierphp_sol_visits" ; //$table_name = "atelierphp_sol_pass_words" ; //on enlève la table si elle existait déjà (mySQLtable_exist($tableName)) ? drop_table($tableName) : print (""); $result = mysqli_query($mysqli,"CREATE TABLE $tableName (VISIT_SESSION_ID CHAR(40) NOT NULL , VISIT_DATE TIMESTAMP, PRIMARY KEY (VISIT_SESSION_ID) )"); if ($result == 1) { echo "table $tableName created<br/>"; } else { echo "error creating the table<br/>"; } @insert_session_id(); //read the table echo "<table border=1 cellspacing=4 cellpadding=5> <tr><th align=center>SESSION_ID</th> <th align=center>TIMESTAMP</th></tr>"; $result = mysqli_query($mysqli,"SELECT * FROM atelierphp_sol_visits "); $fields = mysqli_num_fields($result); while ($row=mysqli_fetch_array($result)) { echo "<tr>"; for($i=0;$i<$fields;$i++) { echo "<td align=center>$row[$i]</td>"; } echo "</tr>"; } echo "</table>"; //--------------------------------------- function insert_session_id() { $result = mysqli_query($mysqli,"INSERT INTO atelierphp_sol_visits (VISIT_SESSION_ID) VALUES ('$_COOKIE[PHPSESSID]')") ; } ?>
|
La table existait déjà Efface table atelierphp_sol_visits Table effacée table atelierphp_sol_visits created
|