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

  • SEARCH
  • Home
  • 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 6019031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:21:42+00:00 2026-05-23T03:21:42+00:00

I have MySQL table with the following structure: +———+————–+——+—–+———+—————-+ | Field | Type |

  • 0

I have MySQL table with the following structure:

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| id      | int(11)      | NO   | PRI | NULL    | auto_increment |
| dept    | varchar(5)   | NO   | MUL |         |                |
| sudoc   | varchar(255) | NO   |     |         |                |
| title   | varchar(255) | NO   |     |         |                |
| type    | tinyint(1)   | NO   |     | 0       |                |
| date    | date         | NO   | MUL |         |                |
| comment | mediumtext   | NO   |     |         |                |
+---------+--------------+------+-----+---------+----------------+

I’m working on a basic search page, which should search the fields “sudoc” and “title” for an arbitrary phrase and return the records that match.

Currently, my database has exactly one record containing the word “Lava” in the title. When I execute the following SQL manually by typing it in on the MySQL command line, it works fine:

PREPARE test FROM "SELECT * FROM govdocs WHERE LCASE(sudoc) REGEXP ? OR LCASE(title) REGEXP ? ORDER BY sudoc";
SET @a = "Lava";
SET @b = "Lava";
EXECUTE test USING @a, @b;

It returns the one matching record.

But then I execute this PHP:

<?php

$DSN = "mysql:host=db.example.edu;port=3306;dbname=govdocs";
$DB = new PDO($DSN, "govdocs", "password", array(PDO::ATTR_PERSISTENT => true));

$SQL = "SELECT * FROM govdocs WHERE LCASE(sudoc) REGEXP :phrase ";
$SQL .= "OR LCASE(title) REGEXP :phrase ORDER BY sudoc";

$query = $DB->prepare($SQL);

$query->execute(array(':phrase' => "Lava",));

if($query){
    $results = $query->fetchall(PDO::FETCH_ASSOC);
    print "There are ".count($results)." results.";
} else {
    print $DB->errorInfo();
}

print "\n";

And it returns 236 results. The “Lava” record is not one of them.

I’ve tried it with other phrases, and the results are not at all consistent.

  • A search for any single-letter character returns seemingly sane results
  • A search for any TWO characters returns 238 results, give or take 5
  • A search for any THREE OR MORE characters returns 236 results

As far as I can tell, the SQL works just fine when I do it manually on the database server. Things get wonky only when it’s executed by PHP.

At this point, I have no idea what’s going on. What am I missing?

EDIT:

Here’s a new test case which tries a query from PHP without bound parameters, as suggested by QTax:

<?php

$DSN = "mysql:host=db.example.edu;port=3306;dbname=govdocs";
$DB = new PDO($DSN, "govdocs", "password", array(PDO::ATTR_PERSISTENT => true));

// First, do it with a static query -- no bound parameters.
$SQL = "SELECT * FROM govdocs WHERE LCASE(sudoc) REGEXP 'Lava' ";
$SQL .= "OR LCASE(title) REGEXP 'Lava' ORDER BY sudoc";

$Query = $DB->prepare($SQL);
$Query->execute();

$results = $Query->fetchall(PDO::FETCH_ASSOC);
print "There are ".count($results)." results for a query with no bound parameters.\n";

// Then do it WITH bound parameters
$SQL2 = "SELECT * FROM govdocs WHERE LCASE(sudoc) REGEXP :phrase ";
$SQL2 .= "OR LCASE(title) REGEXP :phrase ORDER BY sudoc";

$Query = $DB->prepare($SQL2);
$Query->execute(array(':phrase' => "Lava",));

$results = $Query->fetchall(PDO::FETCH_ASSOC);
print "There are ".count($results)." results for a query WITH bound parameters.";

print "\n";

And the output when I run this is:

There are 1 results for a query with no bound parameters.
There are 236 results for a query WITH bound parameters.

There is something weird going on with bound parameters. I just checked the server’s PHP version with php -v, and it said:

PHP 5.1.6 (cli) (built: Nov 13 2010 16:05:12)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

5.1.6 is nearly five years old. I wonder if this is some kind of ancient bug that’s been fixed in newer versions?

  • 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-23T03:21:42+00:00Added an answer on May 23, 2026 at 3:21 am

    Try this:

    $sql = "SELECT * FROM govdocs WHERE sudoc REGEXP ? OR title REGEXP ? ORDER BY sudoc";
    $param = "Lava";
    
    $query = $DB->prepare($sql);
    $query->execute(array($param, $param));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
This is for MySQL and PHP I have a table that contains the following
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
Let's say I have the following MySQL table: id | species ------------ 1 |
Assume the following in MySQL: CREATE TABLE users ( id integer auto_increment primary key,
I have the following tables in MySQL: team: id, name, [more stuff] person: id,
I have a MySQL table with approximately 3000 rows per user. One of the
I have a MySQL table containing domain names: +----+---------------+ | id | domain |
I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION
I have a mysql table that relies on the unix epoch time stamp equivalent

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.