I’m building a basic PHP website to display a calendar of appointments. The data consists of month, day, hour, event name, and description, and since I’m still learning MySQL, I considered using a Google Sheets spreadsheet as the database.
Here are a few reasons behind this choice:
- Anyone can easily edit the spreadsheet
- There’s no need to develop an admin interface
- It may be safer given my current MySQL skills
Google Sheets can export data in CSV or XML formats. Is it practical to use fgetcsv for reading the data? How can I effectively parse it, considering the low traffic?
Below is a sample code snippet I’m thinking of:
$data = fgetcsv($file);
function getEventInfo($m, $d, $h) {
global $data;
foreach ($data as $row) {
if ($row[0] == $m && $row[1] == $d && $row[2] == $h) {
return [$row[3], $row[4]];
}
}
return null;
}
Does this approach seem viable, or is there a better method?
While using Google Sheets as a database for a small PHP website is possible, it’s not ideal for long-term or scalable solutions. I’ve experimented with this approach and found it has limitations.
Your code snippet seems functional for basic operations, but consider efficiency. Loading and parsing the entire CSV on each request could slow down your site as the dataset grows. Instead, you might want to implement a caching mechanism or periodically sync the data to a local file.
Security is another concern. Ensure your Google Sheet’s sharing settings are properly configured to prevent unauthorized access. Also, be cautious about potential injection attacks when handling user inputs.
Ultimately, I’d recommend investing time in learning MySQL. It offers better performance, security, and scalability. Plus, the skills you’ll gain will be invaluable for future projects. Consider this Google Sheets approach as a temporary solution while you develop your database skills.
I’ve actually used Google Sheets as a makeshift database for a small project before, and while it can work, there are some drawbacks to consider.
On the plus side, it’s super easy for non-technical folks to update the data. However, I ran into performance issues as my dataset grew. The approach you outlined could work for a small number of entries, but it might get sluggish with larger datasets.
One thing I’d suggest is caching the data locally. Instead of fetching from Google Sheets on every request, you could set up a cron job to download the CSV periodically and store it on your server. This would improve response times significantly.
Also, be aware that if multiple users are updating the sheet simultaneously, you might encounter data inconsistencies. It’s not a deal-breaker for a small project, but something to keep in mind.
Ultimately, while this approach can work as a temporary solution, I’d recommend transitioning to a proper database as you learn MySQL. It’ll give you valuable experience and more flexibility in the long run.
hey, i’ve tried something similar before. it can work for small stuff, but watch out for slowdowns with bigger datasets. maybe think about caching the data locally? also, google sheets can be finicky with multiple people editing at once. it’s ok for now, but definitely learn mysql when u can. it’ll make your life easier in the long run, trust me!