// You'll probably want to replace hostname with localhost in the first parameter.
05
// The PDO options we pass do the following:
06
// \PDO::ATTR_ERRMODE enables exceptions for errors. This is optional but can be handy.
07
// \PDO::ATTR_PERSISTENT disables persistent connections, which can cause concurrency issues in
certain cases. See "Gotchas".
08
// \PDO::MYSQL_ATTR_INIT_COMMAND alerts the connection that we'll be passing UTF-8 data.
This may not be required depending on your configuration, but it'll save you headaches down the road
if you're trying to store Unicode strings in your database. See "Gotchas".
$handle=$link->prepare('select Username from Users where UserId = ? or Username = ? limit ?');
20
21
// PHP bug: if you don't specify PDO::PARAM_INT, PDO may enclose the argument in quotes. This
can mess up some MySQL queries that don't expect integers to be quoted.
22
// See: https://bugs.php.net/bug.php?id=44639
23
// If you're not sure whether the value you're passing is an integer, use the is_int() function.
24
$handle->bindValue(1, 100, PDO::PARAM_INT);
25
$handle->bindValue(2,'Bilbo Baggins');
26
$handle->bindValue(3, 5, PDO::PARAM_INT);
27
28
$handle->execute();
29
30
// Using the fetchAll() method might be too resource-heavy if you're selecting a truly massive
amount of rows.
31
// If that's the case, you can use the fetch() method and loop through each result row one by
one.
32
// You can also return arrays and other things instead of objects. See the PDO documentation
for details.