Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- $db->query() is accessible anywhere in the application where the bootstrap file is included
- */
- ?>
- <?php
- /**
- The default file template, which can be used for each page
- */
- require_once("bootstrap.php");
- require_once("includes/head.php");
- require_once("includes/header.php");
- //setTitle('Events');
- /**
- Starting from here, you can access $db object, and make Database queries,
- the syntax of DB class query method is:
- $db->query($sql, $bindedParameters)
- */
- // example of DB query to select user where id equals 1
- $sql = "SELECT * FROM sj_users WHERE userID = :userID";
- $bindedParameters = array(
- 'userID' => 1 // here you bind parameters, which you define in statement with semicolon, in this case :userID
- );
- $users = $db->query($sql, $bindedParameters); // if you don't bind parameters, you don't need $bindedParameters
- if(!is_null($users)) {
- // loop users
- foreach($users as $user) {
- // you can display user details here
- echo $user->first_name; // etc
- }
- } else {
- echo 'no users found'; // write something
- }
- // also you can do UPDATE, DELETE, INSERT here too, for example
- $db->query('
- INSERT INTO
- sj_messages (body, message_from, message_to, created_at)
- VALUES (:body, :from, :to, NOW())
- ', array(
- 'body' => 'new message',
- 'from' => 1, // user id
- 'to' => 2 // user id
- ));
- ?>
- <section id="content">
- <div class="wrapper">
- <h1 class="content-heading">Events</h1>
- </div>
- </section>
- <?php
- require_once("includes/footer.php");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement