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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:46:07+00:00 2026-05-19T16:46:07+00:00

I’ve edited the question to be more specific and clear I have the following

  • 0

I’ve edited the question to be more specific and clear

I have the following code on a standalone PHP file:

$conn = mysql_connect("localhost", "", "");

mysql_select_db("name", $conn);

$result = mysql_fetch_array(mysql_query("SELECT EVENT_PRIVATE FROM events WHERE EVENT_ID = 68")); 

var_dump($result);

result is NULL

However, if I copy the exact same query to phpMyAdmin, you can see that EVENT_PRIVATE has a value 1 in it.

enter image description here

I have only one db, so I’m definitely using the same db, also, if I select a different column, I can see the correct value.

I don’t get it, do you?

  • 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-19T16:46:07+00:00Added an answer on May 19, 2026 at 4:46 pm

    I’ve tried this on matching versions of PHP and MySQL, and it does seem to be something odd about the way the PHP “mysql” functions handle bit fields, or at least something I don’t understand. And it certainly looks a bit like a bug. It works as I’d expect in the “mysqli” extension. Here’s what I tried:

    <?php
    // mysql: 
    $conn = mysql_connect('localhost', 'test', 'test');
    mysql_select_db("test", $conn);
    $result = mysql_fetch_array(mysql_query('SELECT EVENT_PRIVATE FROM test WHERE id = 2'));
    var_dump($result);
    
    /* Result: 
    array(2) {
      [0]=>
      string(1) ""
      ["EVENT_PRIVATE"]=>
      string(1) ""
    }
    */
    
    // mysqli:
    $mysqli = new mysqli('localhost', 'test', 'test', 'test');
    $mysqli_result = $mysqli->query('SELECT EVENT_PRIVATE FROM test WHERE id = 2');
    $result = $mysqli_result->fetch_array();
    var_dump($result);
    
    /* Result: 
    array(2) {
      [0]=>
      string(1) "1"
      ["EVENT_PRIVATE"]=>
      string(1) "1"
    }
    */
    

    EDIT: Aha!

    The book “High Performance SQL” says ‘MySQL treats BIT as a string type, not a numeric type; when you retrieve a BIT(1) value the result is a string but the contents are the binary value 0 or 1, not the ASCII value “0” or “1”‘.

    I was expecting BIT to be like the SQL Server “bit” data type, which is a single bit designed for storing a boolean true/false (0/1) value. However, in MySQL it’s much more a bitfield — unlike SQL Server, you can have a bit(8) field, for example, which is eight bits long. And MySQL has a specific “boolean” type instead for storing booleans.

    I’m guessing this is the root of what’s going on. Notice that what’s coming back for the mysql result is a string(1) — that’s a one-character long string, not an empty string, which would be string(0). If you look at the value of that single character:

    echo ord($result['EVENT_PRIVATE']); 
    1
    

    …then it’s an ASCII 1!

    So, I’d say what’s happening is probably, oddly, by design. The mysql extension is being very literal about interpreting the bitfield, and giving you a string encoding the actual bits that are stored in the field in MySQL, at the bit level. The mysqli extension is being a bit friendlier, perhaps, and converting the value into a string representation of the bits.

    I’ll leave it to you to experiment with what happens if you grab a bit(8) set to 10101010 using mysql and mysqli…

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a reasonable size flat file database of text documents mostly saved in
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.