reenadak

printing a table using PDO

Sep 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. $DB_SERVER = "mysql.dunglaxx.com";
  2. $DB_USER = "dungla";
  3. $DB_PASS = "password";
  4. $DB_NAME = "dakdata";  
  5.  
  6. try {
  7.     $pdo = new PDO("mysql:host=$DB_SERVER;dbname=$DB_NAME", $DB_USER, $DB_PASS);
  8.  
  9.     $sql = '
  10.         SELECT word, notes
  11.         FROM md_words
  12.         ORDER BY RAND()
  13.         LIMIT 1 ';
  14.  
  15.     $q = $pdo->query($sql);
  16.     $q->setFetchMode(PDO::FETCH_ASSOC);
  17. }
  18. catch (PDOException $e)
  19. {
  20.     die("Could not connect to the database $dbname :" . $e->getMessage());
  21. }
  22.  
  23.    while ($row = $q->fetch())
  24.    {
  25.         // we print the quote ($row[0]) and the author ($row[0])
  26.         $quote = $row['word'];
  27.         $meaning = $row['notes'];  
  28.    }
Add Comment
Please, Sign In to add comment