In DB I have a table with a field called fk_ownerID
. By default, when I add a new table row, the fk_ownerID
is empty. In Toad for MySQL, this is shown as {null}
. If fk_ownerID
is given a value, and I later remove this value, I set fk_ownerID = ""
.
Now, I have the following code:
$result = $dal->getRowByValue('tableName','id', $_POST['myID']);
// Check to see if any rows where returned
if (mysql_num_rows($result) > 0)
{
while ($row = mysql_fetch_array($result))
{
$ownerID = $row["fk_ownerID"];
}
}
Now the variable $ownerID should have a number, or not. But I'm unsure how to check this. Currently I'm doing this:
if ( (strlen($ownerID) == 0) || ($ownerID == '0') || ($ownerID == 'null') )
But I'm pretty sure only one of these tests should be necessary.
What is the best way to check if a row field is empty or null?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…