Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6732361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:38:28+00:00 2026-05-26T10:38:28+00:00

Possible Duplicate: How do I create a PDO parameterized query with a LIKE statement

  • 0

Possible Duplicate:
How do I create a PDO parameterized query with a LIKE statement in PHP?
PHP PDO prepared statement — mysql LIKE query

I’m trying to make a search engine for my website, and right now I’m just trying to make sure the connection is all and well. Here is my code thus far:

EDITED CODE (Still doesn’t work, but here’s where I’m at with the suggestions thus far):

$db = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME, DB_USER, DB_PASS);
$stmt = $db->prepare("SELECT * FROM table_1 WHERE name LIKE ? ORDER BY bid DESC");
$stmt->bindParam(1, "%{$_GET['s']}%", PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll();

I tried to see if the different methods of execute would do anything, but regardless of which way above I write it, I get the same result, nothing. I want the % wildcard in there so it does it’ll search anywhere in name. On that note, am I using it correctly? The thing that confuses me most is when I type in the exact same query into PHPMyAdmin, the query runs through fine, so my guess is that I’m screwing up the PDO somewhere.


EDIT: PHPMyAdmin Query:

SELECT *
FROM table_1
WHERE name LIKE ‘%Test%’
ORDER BY bid DESC
LIMIT 0 , 30

This returns 1 result, as it is expected to. What is different about my code and this query? :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:38:28+00:00Added an answer on May 26, 2026 at 10:38 am

    I don’t really understand what your question is, but I’m guessing you don’t know how to add the %? If so, try this:

    $stmt = $db->prepare("SELECT * FROM table_1 WHERE name LIKE ? ORDER BY bid DESC");
    $stmt->bindValue(1, "%{$_GET['s']}%", PDO::PARAM_STR);
    $stmnt->execute();
    // fetch and win! :-)
    

    A little explanation:
    PDO will quote and escape the parameter ? appropriately. This means, that if you are binding hello, PDO will substitute ? with 'hello' (note the quotes). Therefore, in order to have the % inside the quotes, you will have to add them to what is binded, in this case $_GET['s'].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How I can create installer for website. PHP mysql I'm looking to
Possible Duplicate: PHP method chaining? I had a function for create user, like cruser
Possible Duplicate: PHP : Create array for JSON I have an array like this
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
Possible Duplicate: PHP PDO vs normal mysql_connect So in my application, I accessed the
Possible Duplicate: How do I Create a Comma-Separated List using a SQL Query? I
Possible Duplicate: How do you create optional arguments in php? I built a function
Possible Duplicate: How do I use define_method to create class methods? I am trying
Possible Duplicate: How to create comma separated list from array in PHP? I have
Possible Duplicate: How to create notification icon badge on Android apps (like iPhone) Friends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.