Advertisement
Guest User

STU

a guest
Nov 30th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.53 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.     $db->query() is accessible anywhere in the application where the bootstrap file is included
  5.    
  6. */
  7.  
  8. ?>
  9.  
  10. <?php
  11.  
  12. /**
  13.  
  14.     The default file template, which can be used for each page
  15.  
  16. */
  17.  
  18. require_once("bootstrap.php");
  19. require_once("includes/head.php");
  20. require_once("includes/header.php");
  21.  
  22. //setTitle('Events');
  23.  
  24. /**
  25.  
  26.     Starting from here, you can access $db object, and make Database queries,
  27.     the syntax of DB class query method is:
  28.  
  29.     $db->query($sql, $bindedParameters)
  30.  
  31. */
  32.  
  33. // example of DB query to select user where id equals 1
  34. $sql = "SELECT * FROM sj_users WHERE userID = :userID";
  35. $bindedParameters = array(
  36.     'userID' => 1 // here you bind parameters, which you define in statement with semicolon, in this case :userID
  37. );
  38.  
  39. $users = $db->query($sql, $bindedParameters); // if you don't bind parameters, you don't need $bindedParameters
  40.  
  41. if(!is_null($users)) {
  42.     // loop users
  43.     foreach($users as $user) {
  44.         // you can display user details here
  45.         echo $user->first_name; // etc
  46.     }
  47. } else {
  48.     echo 'no users found'; // write something
  49. }
  50.  
  51. // also you can do UPDATE, DELETE, INSERT here too, for example
  52. $db->query('
  53.     INSERT INTO
  54.         sj_messages (body, message_from, message_to, created_at)
  55.         VALUES (:body, :from, :to, NOW())
  56. ', array(
  57.     'body' => 'new message',
  58.     'from' => 1, // user id
  59.     'to' => 2 // user id
  60. ));
  61.  
  62. ?>
  63.    
  64.     <section id="content">
  65.         <div class="wrapper">
  66.             <h1 class="content-heading">Events</h1>
  67.            
  68.         </div>
  69.     </section>
  70.    
  71. <?php
  72.  
  73. require_once("includes/footer.php");
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement