$res = $DB->query('SELECT COUNT(*) FROM table');
$num_rows = $res->fetchColumn();
or
$res = $DB->prepare('SELECT COUNT(*) FROM table');
$res->execute();
$num_rows = $res->fetchColumn();
You can use this to ask if data exists or is selected, too:
$res = $DB->query('SELECT COUNT(*) FROM table');
$data_exists = ($res->fetchColumn() > 0) ? true : false;
Or with your variables:
$res = $DB->query('SELECT COUNT(*) FROM table');
$message = ($res->fetchColumn() > 0) ? array('status' => 'ok') : array('status' => 'error');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…