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 8796733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:41:25+00:00 2026-06-13T23:41:25+00:00

Possible Duplicate: PDO Database access WHERE title = $title Here is a sample of

  • 0

Possible Duplicate:
PDO Database access WHERE title = $title

Here is a sample of $message’s content :

String(108) “\n cc je t’ai envoy� une invitation A plus :p\n “

Here is the error message :

Fatal error: Call to a member function setFetchMode() on a non-object
in B:\wamp\www\messages.php on line 101

My request that doesn’t work :

    $resultats = $connexion->query("SELECT * FROM messages WHERE message LIKE '%$message%'");
    $resultats->setFetchMode(PDO::FETCH_OBJ);
    $occurences= $resultats->rowCount();

Why does this one work? (I changed $message by a) :

 $resultats = $connexion->query("SELECT * FROM messages WHERE message LIKE '%a%'");
        $resultats->setFetchMode(PDO::FETCH_OBJ);
        $occurences= $resultats->rowCount();
  • 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-06-13T23:41:26+00:00Added an answer on June 13, 2026 at 11:41 pm

    Simply using PDO with the same techniques that were used for mysql_* doesn’t do you any good, you need to take advantage of its parameterized queries:

    $query = $connexion->prepare("SELECT * FROM messages WHERE message LIKE ?");
    $query->setFetchMode(PDO::FETCH_OBJ);
    if($query->execute(array('%'.$message.'%'))) {
        // process
    }
    else {
        // only for debugging purposes, not a live app
        var_dump($connexion->errorInfo());
    }
    

    It performs all necessary escaping automatically and correctly for you on parameters, that you pass via the execute() method.


    As for I used addslashes: That is not safe. Use prepared statements as demonstrated above.

    Unless you are generating SQL – actual SQL logic, not filling in blanks with user generated content – you should never have a need for PHP variables within SQL.

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

Sidebar

Related Questions

Possible Duplicate: PDO support for multiple queries (PDO_MYSQL, PDO_MYSQLND) i have a statement here..
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: PHP PDO bindParam with html content I'm using PDO prepared statement to
Possible Duplicate: Retrieve (or simulate) full query from PDO prepared statement I can't figure
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: PHP PDO vs normal mysql_connect So in my application, I accessed the
Possible Duplicate: PHP PDO: Can I bind an array to an IN() condition? I
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: declare property as object? class core { public $dbh = new PDO(mysql:dbname=newdbnaem;host=1.1.1.1:1111,
Possible Duplicate: MySQL INSERT from a SELECT with PDO I've historically used the mysql_*

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.