Results 1 to 5 of 5

Thread: Best practices way to express simple queries?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default Best practices way to express simple queries?

    I am trying to learn best practices. Is it necessary or advisable to have error handling built into every statement, or is it OK to be more concise? Is there any advantage of one over the other of these 2 ways of doing the same thing? What happens if you remove the error handling and there is an error? Thanks.

    Code:
    $sql = "SELECT COUNT(*) FROM table";
    $result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error()); ?>
    Code:
    $result = mysql_query("SELECT COUNT(*) FROM table");

  2. #2
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Actually, error handling is not necessary. But it is adviseable. Cause, if you have any error it will output the error. But if you won't put error handling, your script won't work, and no errors will be outputted, just blank page. And you won't find where the error is quickly.

  3. The Following User Says Thank You to allahverdi For This Useful Post:

    kuau (08-04-2008)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    So the error handling is solely to help the programmer rather than to help the program? It doesn't do anything to improve the users' experience? If that is the case, then once your code is debugged and working fine, can you remove all that extra verbiage of the error handling? Thanks.

  5. #4
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    I won't advice it. You can have error when you finished work too. It always helps i think.

    Actually, if you want, you can remove it. But... It is your choose...

  6. The Following User Says Thank You to allahverdi For This Useful Post:

    kuau (08-13-2008)

  7. #5
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    620
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    Dear Allahverdi:

    Now I see what you mean. I forgot how awful it is to get that blank page with no hints about what happened. All it took was one to remind me. I've put the error handling back in. Thanks for sharing your experience. e

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •