0

I have a bit type column in database table. First I was having problem saving field which solved by this question Laravel 4.2 BIT datatype issue

But now when I retrieve data i a getting that bit type field as {}.

"active": {}

Please help me if anyone has solution.

Edit: Sorry, the problem is while creating object.

I have a "schedule" table in which I have "active" field which is BIT. When I create new Schedule using laravel eloquent, returned object has 'active' field as emptystring {}, No matter bit value is 0 or 1.

$schedule = Schedule::create($input);

returns

{
      "active": {},
      "cityId": 84,
      "eventdate": "2015-09-01T00:00:00+05:30",
      "updatedon": "2015-09-15 16:53:48",
      "createdon": "2015-09-15 16:53:48"
}
7
  • in that question it self suggested change bit to tinyint right? Commented Sep 15, 2015 at 10:37
  • And show me your query also,we can easily understand your problem Commented Sep 15, 2015 at 10:38
  • change to bit to tinyint is right but i can't change database definition. Commented Sep 15, 2015 at 10:58
  • ok k look at my answer and try. Commented Sep 15, 2015 at 11:00
  • I have edited my question, please look at it. Commented Sep 15, 2015 at 11:33

1 Answer 1

0

I have faced same problem, i have done like this.

Normally i have retrieve like this but failed to get the email data.In this case email datatype is BIT.

$query = "SELECT Username, email FROM users";
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
print_r($row);

after that i have tried like this and it's working fine for me.

$query = "SELECT Username, CAST(email AS unsigned integer) AS emailid FROM users";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.