1

how to check if the database is empty? my point is that the first person will be the administrator. here is my code

 $query="SELECT staffID,name,surname,email FROM stafftable";
        $do=$con->prepare($query);
        $do->execute();
        $record=$do->rowCount();
        if($record>0):

is there a much better option for this?. thanks

4
Contributors
3
Replies
20
Views
2 Years
Discussion Span
Last Post by almostbob
0

Looks good to me... if you have no records, and you have no limiter (where clause), you obviously have nothing in there.

You could also do "select 1 from stafftable limit 1" and it will probably be faster, but if your goal is to use the data (as yours appears to be), then the method you are using seems perfectly fine.

0

Well you could do something like showing some messages to know it like this:

 $query="SELECT staffID,name,surname,email FROM stafftable";
        $do=$con->prepare($query);
        $do->execute();
        $record=$do->rowCount();
        if($record>0){
            echo "Record found";
        }else{
            echo "No record found";
        }
0

important: it works
the code could be tighter,
BUT,
as it is there is no need for commenting, a bonus if/when a change has to be made

Edited by almostbob

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.