Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder Apothem's Avatar
    Join Date
    Mar 2008
    Posts
    380
    Thanks
    36
    Thanked 25 Times in 25 Posts

    MySQL query or fread?

    So lets say my script always connects to the MySQL database at beginning of script.

    Now, what would be faster to obtain data?
    a) Selecting all data from a table with 20 entries
    or
    b) fopen-ing a file and fread-ing it (both binary; 80 chars); also 20 entries.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Depends but if MySQL has the query cached it could be a lot faster. You can time PHP code, your best bet would be to write both and time them. Does any other parts of the page require data from your database? If so the connection time is going to be a cost either way.

    For timing your code see: http://php.net/manual/en/function.microtime.php
    OracleGuy


  •  

    Posting Permissions

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