Shaked Klein Orbach echo 'Just smile';

18Nov/110

PHP: Insert\Update MySQL BIT(1) field

Today I`v noticed to interested things: 

  1. A nice sentence or a motto that I really liked: 

    "When you do a search, and it comes back with no results, it’s a sign that you need to write something." (Taken from Here
     

  2. Didn't find any straight answer on Google for my question: "How to insert\update a bit field with PHP": 

So with MySQL you would use:

INSERT INTO t SET b = b'1'; // Or b'0' 

 And with PHP you would use boolean type: 


//$db instanceof ActiveRecord, that's only for the following example
//you can use other ways to insert\update your MySQL DB. 

$db->insert(array('b'=>true,'c'=>false)); //true = b'1' , false = b'0'

$db->update(array('b'=>true,'c'=>false)); //true = b'1' , false = b'0'

Hope I helped,
Shak.


Posted by Shaked

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.