Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Odczyt danych z bazy danych i wyświetlenie ich
- na końcu pliku trzy.php są kasowane wszystkie rekordy z bazy danych <br>
- Jeśli wywołany zostanie po kolei kilka razy plik jeden.html w <br>
- w odczycie z bazy danych pojawi się kila rekordów<br><br>
- <?php
- $servername = "localhost";
- $database = "idxxxxxxx_esp8266";
- $username = "idxxxxxxx_esp8266restapi";
- $password = "xxxxxxxxxxxxxx";
- // Create a connection
- $conn = mysqli_connect($servername, $username, $password, $database);
- // Check the connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- echo "Connected successfully";
- $sql = " SELECT `nazwa`, `dana` FROM `test`";
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) > 0) {
- // output data of each row
- while($row = mysqli_fetch_assoc($result)) {
- echo "<br>";
- echo "nazwa z bazy: " . $row["nazwa"]. " - dana z bazy: " . $row["dana"]. "";
- // printf("%s (%s)\n", $row["nazwa"], $row["dana"]);
- }
- } else {
- echo "0 results";
- }
- $query = "TRUNCATE table 'test'";
- mysqli_close($conn);
- $servername = "localhost";
- $database = "id20200915_esp8266";
- $username = "id20200915_esp8266restapi";
- $password = "Krzysp_12345678";
- // Create a connection
- $conn = mysqli_connect($servername, $username, $password, $database);
- // Check the connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
- //echo "Connected successfully";
- echo "<br>";
- $sql = "TRUNCATE TABLE test";
- if (mysqli_query($conn, $sql)) {
- echo "Truncated Successfull";
- } else {
- echo "Error: " . $sql . "<br>" . mysqli_error($conn);
- }
- mysqli_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement