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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:47:44+00:00 2026-06-14T18:47:44+00:00

Related question, but not helpful to me: Why cant you pass MYSQL functions into

  • 0

Related question, but not helpful to me: Why cant you pass MYSQL functions into prepared PDO statements?

Here’s the deal: I’m writing an abstraction layer to PHP PDO and implementing a query builder.
This exact problem is occurring only in INSERT statements. Here’s an example of my code:

$db->insert('table_name')
    ->keys(array('abc', 'def', 'ghi'))
    ->values(array($var1, $var2, $var3)) // can take a 2D array if you want to insert multiple rows at the same time
    ->execute();

The underlying code builds the query string with ?’s instead of values. For this particular example the query would result in the following:

INSERT INTO `table_name`
(`abc`, `def`, `ghi`)
VALUES
(?, ?, ?)

Upon calling execute(), it passes the values to PDOStatement::execute() as single dimension array (i.e. all values associated with the question marks are put in a single array). And this is where the problems start – the PDOStatement::execute() does not process MySQL functions as such, but quotes them as strings, thus breaking the query:

INSERT INTO `table_name`
(`abc`, `def`, `ghi`)
VALUES
('123', 456, 'NOW()') -- error, incorrect datetime value: 'NOW()'

The question is – how do I make this work while still maintaining the same interface? I know I could just check if the value of the column is a MySQL function and put it in directly instead of the question mark, but there are many functions one could use there and that would suck.

Edit: so it seems that for now the easiest option would be to simply set the values to leave alone like this: $var3 => 'noquote'. It’s not really a good one, but it works.

  • 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-14T18:47:45+00:00Added an answer on June 14, 2026 at 6:47 pm

    Add another argument for that method:

    • table name
    • values (as associative array)
    • sql (as associative array)

    Keep in mind, that you cannot use ‘?’ when you want to do access the columns, e. g. in COLUMN1 + 1 or COLUMN1 + COLUMN2.

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

Sidebar

Related Questions

Related to my question here but not enough to open a new question. I
The question is closely related to my past question here, but it is not
I am facing a dilemma related to another question but not exactly the same.
I have seen many answers for this type of question but its not related
This is a not related to my project code , but a question came
Not strictly a programming question, but definately programming related. The option to run tests
not much of a programming question, but development related still, I'm starting Android development
I have read other related question but i cant really get them to relate
[This question is related to but not the same as this one .] My
Found related questions but not the exact variant so I am posting a very

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.