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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:09:45+00:00 2026-05-27T05:09:45+00:00

From the PHP manual , it states that: PDO::ATTR_EMULATE_PREPARES Enables or disables emulation of

  • 0

From the PHP manual, it states that:

PDO::ATTR_EMULATE_PREPARES Enables or disables emulation of prepared
statements. Some drivers do not support native prepared statements or
have limited support for them. Use this setting to force PDO to either
always emulate prepared statements (if TRUE), or to try to use native
prepared statements (if FALSE). It will always fall back to emulating
the prepared statement if the driver cannot successfully prepare the
current query. Requires bool.

I have a query that goes like this:

$type = PDO::PARAM_INT;
if($_POST['code'] == "") $type = PDO::PARAM_NULL;

$stmt = $dbh->prepare("UPDATE Product SET code=? WHERE id=?");
$stmt->bindValue(1, $_POST['code'], $type);
$stmt->bindValue(2, $_SESSION['id'], PDO::PARAM_INT);
$stmt->execute();

I realise that without setting the following statement, I would get a '0' instead of a NULL value (when $_POST['code'] == "") into my database using the code above. Why is that so?

$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

UPDATE:

Although disabling of the emulation works for me, I would prefer to use it because like the OP in this question, basically all my queries are only executed once per script execution. Therefore, having the statements prepared does not gain me any advantage and creates unnecessary calls to the database as shown in the general query log below:

Emulation Disabled
22 Connect user@localhost on Database
22 Prepare UPDATE Product SET code=? WHERE id=?
22 Execute UPDATE Product SET code='abc' WHERE id='123'
22 Close stmt   
22 Quit

Emulation Enabled
22 Connect user@localhost on Database
22 Query UPDATE Product SET code='abc' WHERE id='123'
22 Quit

Any help to solve the NULL issue is greatly appreciated.

  • 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-27T05:09:46+00:00Added an answer on May 27, 2026 at 5:09 am

    Try bind null for PDO::PARAM_NULL.

    $type = PDO::PARAM_INT;
    if($_POST['code'] == "") {
        $_POST['code'] = null;
        $type = PDO::PARAM_NULL;
    }
    
    $stmt = $dbh->prepare("UPDATE Product SET code=? WHERE id=?");
    $stmt->bindValue(1, $_POST['code'], $type);
    $stmt->bindValue(2, $_SESSION['id'], PDO::PARAM_INT);
    $stmt->execute();
    

    In fact, it seems you don’t need use PDO::PARAM_NULL, the code below will also insert null.

    $stmt->bindValue(1, $_POST['code'] ? $_POST['code'] : null, PDO::PARAM_INT);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The PHP manual states It is not possible to use $this from anonymous function
From the PHP manual, session.gc_probability and session.gc_divisor state that gc will occur based on
The PHP manual for anonymous functions (ie, Closures) states that: Anonymous functions are currently
I have the following piece of code taken from the PHP manual on the
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
From PHP.net: http://www.php.net/manual/en/function.pfsockopen.php I understand the gist of what this function accomplishes, but I'm
for example consider an url from php.net, let's be it: http://pl2.php.net/manual/en/function.time.php gmt time when
I'm working on porting some PHP code to C, that contacts a web API.
while reading about declare construct from php manual i tried the following example using
while reading abt array_filter() from php manual,came to face example to demostrate the same

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.