Advertisement
Guest User

Untitled

a guest
Jan 29th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. //Our connection details.
  5. $host = 'xxx';
  6. $user = 'xxx';
  7. $password = 'xxx';
  8. $database = 'xxx';
  9.  
  10. //An options array.
  11. //Set the error mode to "exceptions"
  12. $pdoOptions = array(
  13.     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  14.     PDO::ATTR_EMULATE_PREPARES => false
  15. );
  16.  
  17. //Connect
  18. $pdo = new PDO("mysql:host=$host;dbname=$database", $user, $password, $pdoOptions);
  19.  
  20.  
  21. //Selecting multiple rows from a MySQL database using the PDO::query function.
  22. $sql = "SELECT * FROM `messeges` ORDER BY mID DESC LIMIT 15";
  23.  
  24. foreach($pdo->query($sql, PDO::FETCH_ASSOC) as $row){
  25.     echo $row['MYUSERNAME'] . ': ';
  26.     echo $row['MESSEGE'] . '|';
  27. }
  28. $pdo = null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement