/ Published in: PHP

This is the basic code that you need to know to connect and list data with PDO.
Don't use de old method (mysql_connect and mysqli_connect) to connect and interact with databases.
Don't use de old method (mysql_connect and mysqli_connect) to connect and interact with databases.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* Connection string */ $db = new PDO('mysql:host=localhost;dbname=YOUR_DB_NAME', 'root', 'YOUR_DB_PASSWORD', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $stmt = $db->prepare('select * from your_table'); $stmt->execute(); // Get all records $result = $stmt->fetchAll(); echo '<pre>';
Comments
