PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE auction ( id INT AUTO_INCREMENT, name VARCHAR(10), PRIMARY KEY (id) ); INSERT INTO auction(name) VALUES ('bar'), ('fee'), ('foo'), ('bum'), ('bu%'), ('fum'), ('boo'), ('bee');
Copy Clear
Copy Format Clear
<?php $query = 'bum'; $escaped = str_replace(['!', '%', '_'], ['!!', '!%', '!_'], $query); echo "Escaped: $escaped\n\n"; $stmt = $pdo->prepare("SELECT * FROM auction WHERE name LIKE ? ESCAPE '!'"); $stmt->execute(["%$escaped%"]); foreach ($stmt as $i => $row) { echo "$i: " . var_export($row, true) . "\n"; } echo "\n---\n"; $stmt->execute(["%$escaped%"]); $i = 0; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo "$i: " . var_export($row, true) . "\n"; ++$i; } echo "\n---\n"; $stmt->execute(["%$escaped%"]); var_export($stmt->fetchAll(PDO::FETCH_ASSOC));
Show:  
Copy Clear