This question may have been asked before, but it’s not in the same manner. I’m trying to check if all the fields in a mysql table are empty.
There’s an ID fields which is set as Primary key and has an autoindex, so it has a value, but the rest of the columns are empty by default.
This is what I have so far:
public function check_empty_table() {
$sql = "SELECT * FROM products";
$fields = array();
if ($stmt = $this->connect->prepare($sql)) {
$stmt->execute();
while ($stmt->fetch()) {
}
}
}
What else should I add ? It doesn’t matter what I grab or how, I just want to throw all the data in that array and then check if the array is empty.
The cool thing about COUNT() is that it doesn’t count NULL values.
So, if you do this for each column other than the ID column, and you get zero for each, then it’s “blank”: