asimryu

PHP SIMPLE PDO EXAMPLE

May 22nd, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>news list</title>
  6. </head>
  7. <body>
  8. <div id="newslist">
  9. <?php
  10.     $db = new PDO( 'mysql:host=localhost;dbname=web;charset=utf8', 'root', '');
  11.     $rs = $db->query("select no, title from news");
  12.     if( $rs->rowCount() ) {
  13.         $rows = $rs->fetchAll(PDO::FETCH_ASSOC);
  14.         foreach($rows as $r) {
  15.             echo $r['title']."<br>";
  16.         }
  17.     }
  18.     //$count = $db->exec("DELETE FROM news WHERE no > 9");
  19.     //print("deleted record : " . $count . "<br>");
  20.     $count = $db->exec("insert into news set title='hello webdesign',content='hahahahahahahahahahhaahahah'");
  21.     print("inserted record : " . $count);
  22. ?>
  23. </div>
  24. </body>
  25. </html>
Advertisement
Add Comment
Please, Sign In to add comment