|  | 12 | Accessing MySQL database from php: | 
          
            |  | 13 |  | 
          
            |  | 14 | Make sure MySQL is configured first. Refer to MySQL page | 
          
            |  | 15 | MySQL (MariaDB) | 
          
            |  | 16 |  | 
          
            |  | 17 | Create a simple test php file to read from the database | 
          
            |  | 18 |  | 
          
            |  | 19 | {{{ | 
          
            |  | 20 | cd /usr/share/apache2/default-site/htdocs | 
          
            |  | 21 | nano 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'); | 
          
            |  | 34 | if(!$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 |  | 
          
            |  | 55 | Test with PC on same network as 825. | 
          
            |  | 56 |  | 
          
            |  | 57 |  |