Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //connection details
- $host = 'localhost';
- $dbname = 'database name';
- $dbusername = 'database username';
- $password = 'db password';
- //make a connection
- $db = new PDO("mysql:$host=;port=8889;$dbname=", $dbusername, $password);
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- //get records from database if there's an error catch it.
- try {
- //select columns to select from the database table
- $stmt = $db->query('SELECT id, name, address FROM table');
- //loop through the rows
- while($row = $stmt->fetch()){
- //print the output
- echo '<p>';
- echo 'id: '.$row['id'].'<br />';
- echo 'name: '.$row['name'].'<br />';
- echo 'addres: '.$row['address'];
- echo '</p>';
- }// end the while
- } catch(PDOException $e) {
- //display any error messages
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement