Jump to content

mysqli LIKE query does not work


aHMAD_SQaLli
Go to solution Solved by Barand,

Recommended Posts

Hello every one

$db_mysqli_connect = mysqli_connect("localhost", "root", "root", "PSE_database");
if (mysqli_connect_errno($db_mysqli_connect)) {
echo 'Some error occurred during connection to the database';}
$LIKE = "rammstein";
if ($stmt = mysqli_prepare($db_mysqli_connect, "SELECT document_title FROM pse_docs WHERE document_title LIKE ?")) {
    mysqli_stmt_bind_param($stmt, "s", $LIKE);
    mysqli_stmt_execute($stmt);
    $result = mysqli_stmt_get_result($stmt);
    if(mysqli_num_rows($result) !== 0) {
        while ($row = mysqli_fetch_assoc($result)){
			echo $row['document_title']. "<br>";
			}
		}
    else { echo "Not Found"; }
}
else { trigger_error('Unable query users table: ' . mysqli_error($db_mysqli_connect)); }
mysqli_free_result($result);
mysqli_stmt_close($stmt);
mysqli_close($db_mysqli_connect);

this code does not work, it returns nothing,

btw, document title is Rammstein !

 

Thanks.

Link to comment
Share on other sites

  • Solution

You use LIKE with wildcards when you are searching for something that contains the search string. If you are looking for an exact match use "=". In this case it could be that perhaps the title in the db has extra space character at the end.

 

Try this with your current query

$LIKE ="%rammstein%";

If that fails it could be you are using a case-sensitive collation.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.