Advertisement
Guest User

Untitled

a guest
Dec 15th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. $st = $db->prepare("SELECT * FROM table WHERE name LIKE ?");
  2. $st->execute(array('%'.$test_string.'%'));
  3.  
  4. $test_string = '%' . $test_string . '%';
  5. $st->bind_param('s', $test_string);
  6. $st->execute();
  7.  
  8. # oracle
  9. SELECT * FROM table WHERE name LIKE '%' || :param || '%'
  10. # mysql
  11. SELECT * from table WHERE name LIKE CONCAT('%', :param, '%')
  12.  
  13. "SELECT * FROM table WHERE name LIKE CONCAT(CONCAT('%',?),'%')"
  14.  
  15. $stmt = mysqli_prepare($con,"SELECT * FROM table WHERE name LIKE ?");
  16. $newParameter='%'.$query.'%';
  17. mysqli_stmt_bind_param($stmt, "s", $newParameter);
  18. mysqli_stmt_execute($stmt);
  19.  
  20. $dbPassword = "pass";
  21. $dbUserName = "dbusr";
  22. $dbServer = "localhost";
  23. $dbName = "mydb";
  24.  
  25. $connection = new mysqli($dbServer, $dbUserName, $dbPassword, $dbName);
  26.  
  27. if($connection->connect_errno)
  28. {
  29. exit("Database Connection Failed. Reason: ".$connection->connect_error);
  30. }
  31. $tempFirstName = "reuel";
  32. $sql = "SELECT first_name, last_name, pen_name FROM authors WHERE first_name LIKE CONCAT(CONCAT('%',?),'%')";
  33. //echo $sql;
  34.  
  35. $stateObj = $connection->prepare($sql);
  36. $stateObj->bind_param("s",$tempFirstName);
  37. $stateObj->execute();
  38. $stateObj->bind_result($first,$last,$pen);
  39. $stateObj->store_result();
  40.  
  41. if($stateObj->num_rows > 0) {
  42. while($stateObj->fetch()){
  43. echo "$first, $last "$pen"";
  44. echo '<br>';
  45. }
  46. }
  47.  
  48. $stateObj->close();
  49. $connection->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement