Revision: 68853
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 6, 2015 02:32 by snstro
Initial Code
<?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>'; print_r($result); // Show a data array with results
Initial URL
Initial Description
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.
Initial Title
Simple PDO Connection and select
Initial Tags
mysql, php, data, list
Initial Language
PHP