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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:29:48+00:00 2026-05-31T04:29:48+00:00

I have a problem in a php script where I am using PDO to

  • 0

I have a problem in a php script where I am using PDO to access my database. I can’t seem to get PDO to escape my string when I use prepare()or execute()in PDO. I’ve looked all over and I haven’t found an answer to this problem because everywhere I look it says PDO automatically escapes the strings.
Here’s my code :

$statement = $db->prepare("INSERT INTO Table (ID, Column1, Column2) VALUES (NULL, '$var1', '$var2')");
$query->execute();

Let’s admit $var1 = "abc'def" and $var2 = "123" The problem is I get an error message because the quote wasn’t escaped.

Error : SQLSTATE[42000]: Syntax error or access violation: 1064 You
have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near ‘def’,
‘123’)’ at line 1

I’ve also tried using the query() method but same prpblem with the quotes.
I really don’t understand and it’s frustrating. Thanks for any help.

  • 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-31T04:29:49+00:00Added an answer on May 31, 2026 at 4:29 am

    Try this:

    # Took out ID, as it should be auto_increment and handled by database
    $statement = $db->prepare("INSERT INTO Table (Column1, Column2) VALUES (:col1, :col2)");
    
    $statement->bindValue(':col1', $var1, PDO::PARAM_STR);
    $statement->bindValue(':col2', $var2, PDO::PARAM_INT);
    
    $statement->execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem using some php functions on a string i get from
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I have a problem using ajax (jquery) and recursion. I call a php script
I have a problem with charset on a php script using jQuery for AJAX
I am having a problem using PHP's PDO object to prepare an update statement
I have have problem while using the cURL in my php script. Wheni used
I have a php script the I often run using CLI (regular ssh terminal).
I have a php script, which downloads, rescales and stores an image using the
i have a problem. I have made a PHP proxy to get json data
I have a problem, I use pcntl_fork to fork a process in PHP, $pid

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.