Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $st = $db->prepare("SELECT * FROM table WHERE name LIKE ?");
- $st->execute(array('%'.$test_string.'%'));
- $test_string = '%' . $test_string . '%';
- $st->bind_param('s', $test_string);
- $st->execute();
- # oracle
- SELECT * FROM table WHERE name LIKE '%' || :param || '%'
- # mysql
- SELECT * from table WHERE name LIKE CONCAT('%', :param, '%')
- "SELECT * FROM table WHERE name LIKE CONCAT(CONCAT('%',?),'%')"
- $stmt = mysqli_prepare($con,"SELECT * FROM table WHERE name LIKE ?");
- $newParameter='%'.$query.'%';
- mysqli_stmt_bind_param($stmt, "s", $newParameter);
- mysqli_stmt_execute($stmt);
- $dbPassword = "pass";
- $dbUserName = "dbusr";
- $dbServer = "localhost";
- $dbName = "mydb";
- $connection = new mysqli($dbServer, $dbUserName, $dbPassword, $dbName);
- if($connection->connect_errno)
- {
- exit("Database Connection Failed. Reason: ".$connection->connect_error);
- }
- $tempFirstName = "reuel";
- $sql = "SELECT first_name, last_name, pen_name FROM authors WHERE first_name LIKE CONCAT(CONCAT('%',?),'%')";
- //echo $sql;
- $stateObj = $connection->prepare($sql);
- $stateObj->bind_param("s",$tempFirstName);
- $stateObj->execute();
- $stateObj->bind_result($first,$last,$pen);
- $stateObj->store_result();
- if($stateObj->num_rows > 0) {
- while($stateObj->fetch()){
- echo "$first, $last "$pen"";
- echo '<br>';
- }
- }
- $stateObj->close();
- $connection->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement