Changes between Version 1 and Version 2 of Docs/825gen2/Dev/Networking/PHP


Ignore:
Timestamp:
11/09/23 13:00:17 (12 months ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/825gen2/Dev/Networking/PHP

    v1 v2  
    1010
    1111
     12Accessing MySQL database from php:
     13
     14Make sure MySQL is configured first. Refer to MySQL page
     15MySQL (MariaDB)
     16
     17Create a simple test php file to read from the database
     18
     19{{{
     20cd /usr/share/apache2/default-site/htdocs
     21nano readmysql.php
     22}}}
     23
     24{{{
     25<!DOCTYPE html>
     26<html lang="en">
     27<head>
     28  <title>825 MySQL Test</title>
     29</head>
     30<body>
     31
     32<?php
     33$conn = mysqli_connect('127.0.0.1', 'dbuser', '81440', 'test');
     34if(!$conn) {
     35   echo 'Connection error: ' . mysqli_connect_error();
     36} else {
     37   $sql = 'select * from test_tbl;';
     38   $result = $conn->query($sql);
     39   if($result->num_rows > 0) {
     40      echo '<table><tr><th>Title</th><th>Description</th></tr>';
     41      while($row = $result->fetch_assoc()) {
     42          $title = $row['title'];
     43          $description = $row['description'];
     44          echo '<tr><td>' . $title . '</td><td>' . $description . '</td></tr>';
     45      }
     46      echo '</table>';
     47   }
     48}
     49?>
     50
     51</body>
     52</html>
     53}}}
     54
     55Test with PC on same network as 825.
     56
     57