Friday, 15 July 2011

php - Check if 'pdo->query foreach' return null -



php - Check if 'pdo->query foreach' return null -

the database fine can't figure why $row cannot recognized null.

i have code:

$pdo = new pdo("mysql:host=" . $this->hostname . ";dbname=" . $this->dbname, $this->username, $this->password); foreach($pdo->query('select * people name="joshua"') $row): if($row['name'] != null): echo "we have 1 joshua"; else: echo "we not have joshua"; endif; endforeach;

when run script got the: "we have 1 joshua" message;

when alter name="joshua" in pdo->query name not exist on database not receive "we not have joshua" message;

any hints deal this?

i want create statement command if foreach homecoming null or not.

thanks in advance , sry bad english.

how this?

foreach($pdo->query('select count(*) totalcount people name="joshua"') $row): if($row['totalcount'] != 0): echo "we have 1 joshua"; else: echo "we not have joshua"; endif; endforeach;

php mysql sql pdo

No comments:

Post a Comment