Чтение записей из таблицы базы данных MySQL
(файл index.php)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <form method="post" action="add.php"> <table> <tr> <td>Название:</td> <td> <input type="text" name="title" size='30' /> </td> <td> <input type="submit" name="submit" value="Создать" /> </td> </tr> </table> </form> <br/> <table border=1> <?php $user = 'root'; $pass = ''; try { $dbh = new PDO('mysql:host=localhost;dbname=test;charset=utf8', $user, $pass); foreach($dbh->query('SELECT * from `m_category`') as $row) { $id = $row['id']; echo "<tr>"; echo "<td>",$id,"</td>"; echo "<td>", $row['title'],"</td>"; echo "<td><a href ='edit.php?id=$id'>Редактировать</a></td>"; echo "<td><a href ='delete.php?id=$id'> <center>Удалить</center></a></td>"; echo "</tr>\n"; } $dbh = null; } catch (PDOException $e) { print "Ошибка: " . $e->getMessage() . "<br/>"; die(); } ?> </table> </body> </html>