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 = 'b%'; $escaped = str_replace(['!', '%', '_'], ['!!', '!%', '!_'], $query); echo "Escaped: $escaped\n\n"; $stmt = $pdo->prepare("SELECT name FROM auction WHERE name LIKE ? "); $stmt->execute(["%$escaped%"]); var_export($stmt->fetchAll(PDO::FETCH_COLUMN));
Show:  
Copy Clear