1
2
3
4
5 <?php
6require_once 'dbconfig.php';
7
8try {
9 $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
10
11 $sql = 'SELECT lastname,
12 firstname,
13 jobtitle
14 FROM employees
15 ORDER BY lastname';
16
17 $q = $pdo->query($sql);
18 $q->setFetchMode(PDO::FETCH_ASSOC);
19} catch (PDOException $e) {
20 die("Could not connect to the database $dbname :" . $e->getMessage());
21}
22?>
23<!DOCTYPE html>
24<html>
25 <head>
26 <title>PHP MySQL Query Data Demo</title>
27 <link href="css/bootstrap.min.css" rel="stylesheet">
28 <link href="css/style.css" rel="stylesheet">
29 </head>
30 <body>
31 <div id="container">
32 <h1>Employees</h1>
33 <table class="table table-bordered table-condensed">
34 <thead>
35 <tr>
36 <th>First Name</th>
37 <th>Last Name</th>
38 <th>Job Title</th>
39 </tr>
40 </thead>
41 <tbody>
42 <?php while ($row = $q->fetch()): ?>
43 <tr>
44 <td><?php echo htmlspecialchars($row['lastname']) ?></td>
45 <td><?php echo htmlspecialchars($row['firstname']); ?></td>
46 <td><?php echo htmlspecialchars($row['jobtitle']); ?></td>
47 </tr>
48 <?php endwhile; ?>
49 </tbody>
50 </table>
51 </body>
52</div>
53</html>
1$pdo = new PDO('mysql:host=$host; dbname=$database;', $user, $pass);
2$stmt = $pdo->prepare('SELECT * FROM auction WHERE name = :name');
3$stmt->bindParam(':name', $_GET['searchdivebay']);
4$stmt->execute(array(':name' => $name);
1$stmt = $pdo->prepare("SELECT * FROM users LIMIT :limit, :offset");$stmt->execute(['limit' => $limit, 'offset' => $offset]); $data = $stmt->fetchAll();// and somewhere later:foreach ($data as $row) { echo $row['name']."<br />\n";}