Insert to database variable with single quotes

Using your code, with a unique index on the name column, only takes 7 seconds for 300 rows inserted into an empty table for me. What else is the code on the page doing?

Here are some application issues and improvements for the code -

  1. The function should be general-purpose and accept a relative directory/path and the database connection as call-time parameters.
  2. The function name should not end in a number, indicating you are probably going to copy/paste the definition a number of times, with a different hard-coded directory/path value in each one.
  3. You should only store a minimum amount of data in the database table. The full server directory/path is application specific and should not be stored in the database (if you move the application to a different server/path, the dir column data will be wrong.) You should only store the filename and the relative path in the database table.
  4. You should prepare and bind the inputs only once, before the start of the looping. This will result in a small performance gain.
  5. The $filename; variable on a line by itself does nothing and should be removed.
  6. You can achieve a small performance gain by just using glob() to get a list of .mp3 files in the directory, then loop over those matching files. No need for the pathinfo() and the if() conditional logic.
1 Like

When I go home, I print all code. May be my code have something error. Thanks for all

Sponsor our Newsletter | Privacy Policy | Terms of Service