0

I am trying to select empty columns using datamapper.

Below is what I tried:

  $u = new test();
  $u->where("id",1);
  $u->select('name');
  $u->get();
  $u->result_count();

I am trying to find out whether the name column is empty or not.

If the name is present in the database, it will insert the name or it will be empty.

Thanks

tereško
  • 58,060
  • 25
  • 98
  • 150
Shazad Maved
  • 235
  • 1
  • 5
  • 12
  • I'm not sure where you want to test for empty name. You mean in SQL `where`, or in php land? The `result_count()` in your example suggests that in sql, but then why not just `$u->where('name', '')`? – complex857 Apr 24 '13 at 09:52

1 Answers1

0

I suggest using the exists method.

$u = new text();
$u->where("id",1);
$u->select('name');
$u->get();

if($u->exists()){
//Code if TRUE
}else{
//Code if FALSE
}

You can find more about datamapper utilities here: http://datamapper.wanwizard.eu/pages/utility.html#exists

Hope this helps!

Crowlix
  • 1,269
  • 9
  • 19