this is my first post, so please bear with me... perhaps the solution I'm looking for is really really easy?
I've got a database holding the address and contact details of 3500 businesses. Instead of querying the db every time for a certain business detail, I want to write the query results for ("SELECT * FROM tablename") to a file with php using fopen/fwrite.
For some reason, the query is taking too long so the file doesn't get written. When I limit the query to 100 or so, it works perfectly. I wouldn't think 3500 rows was too many... can you think of a reason why this is happening, or how I can optimize my query?
Any insight into my problem would be greatly appreciated. Thank you!
Hm, is that not the right thing to do? My end purpose is to create a facility that emails each business and displays their address/details in the body of the email for them to approve or amend. I don't know how else to get the info to display each business's unique details?
Hello! As to why it works for 100 and not for all is probably because PHP has a configurable setting to time out on queries (php.ini) so for whatever reason, it's not able to finish in time. As for sending customizing e-mail messages, PHP can do this easily with the mail() function. You would SELECT your records, loop through them, and send mail() to each using each record's data. The only downside is that the e-mails are auto-generated by the server, so some users' mail clients may suspect it is SPAM. I do not think I would use flat text files, however.
Pulling 3500 rows from a table isn't too hazardous, so it might be worth looking at your MySQL/PHP setup to determine if there is anything holding this back. If you run the query from SQL command line does it return all the results in a reasonable time?