I am working on a website and using git. The repo is public but I don't want the mySQL info to be part of it. Should I just put the connection code in a file then block that file with .gitignore?
Is there a better, more sophisticated best practice or is it that simple?
I wish git handled mySQL better by default. I can easily save the files but not the database, but as the app grows those files will be dependent on the database. Short of using flat files or some complex mySQL dumping, I haven't found a good solution. I think you can use a db engine that uses files instead of databases, but I've use mySQL for so long I hate changing everything just to accommodate git. Is there a way have git do I mySQL dump/import whenever a push / deploy is performed?
Sorry for the 3 questions in 1 but I didn't want to make 3 threads, especially when I think I know the answer to question 1. This is my first real project in years and I almost feel like I'm having to relearn programming. So much stuff is new - flex box and flex grid and php8.2 in stead of 5 and msqli - everything is better, either a lot or just slightly, but it's so much different stuff all at once. I hope my 38 year old brain can still get it. I'm not able to do the 12 hour coffee flued marathons like when I was in my 20s, I hope programming isn't just a young man's game but I'm trying to work smarter, getting up something and marketing it instead of just cranking out tons of needless code.
Create .env file in your project root. in php use $_ENV or getenv(). add .env file to .gitignore to prevent from being included in Git.
use package vlucas/phpdotenv for PHP for others check equivalent.
Save your credentials in .env as below:
DB_HOST=your_host
DB_USER=your_user
DB_PASS=your_password
DB_NAME=your_database