1. Intro
I understand that this is a really old post (2013) and I am commenting on 2024, but I am going to write a reply anyway, for anyone new looking to do something similar to this.
I also want to mention that people here are recommending not to do what the OP is wanting, for the wrong reasons. From what I understand, you want each school to have its data separated. And that's not bad to try and implement.
2. When & Why you would need this
You might want to do something like this, for privacy reasons, or perhaps, due to limitations opposed by your hosting provider. For example, with Hostinger, you can have unlimited databases with 100 GB total storage for their premium plan, but each Database is capped at 3GB each. So if one school (in this case), has a lot of data, you would want to create individual databases for each school so that the limit is not reached/exceeded.
3. Main issue with this approach (Spoiler Alert: It's NOT because of SQL Injection)
The main issue I find with this, is not SQL Injection or anything of the sort, as you can easily prevent that with PHP. There are methods you can wrap your data with, to secure your fields, you can even create an API to handle this for you and perform validation checks before running the query.
I would say the main issue is with database management after a database has been created. Even if a customer created a new database by adding these details in, they would not be able to have secure access to the database without some sort of account, user, database name and password. And exposing those details about the database is a recipe for disaster.
You can't just create a database and call it a day! You need to ensure it is secure and protected from outside resources.
4. My recommendation for a solution
I believe the best scenario for something like this, would be to create 2 products; (1) super admin dashboard, and (2a) admin dashboard or (2b) customer dashboard.
4.1. How would this look like
The super admin dashboard would be responsible for managing all created databases per school. It would have its own database, to store other database's details (encrypted for extra security).
Users, instead of filling in the database name on a form, would instead provide you with details about their school (e.g. name, address, etc). Based on those details you would use your super admin dashboard to create and manage that database.
You would then also need an API that can be called from the customer dashboard, with an authentication token, and if the token is valid, then you would authorize the user to access data from the database to their customer dashboard.
The super admin dashboard, would also need to be hosted somewhere secure, with a sign-in and 2FA (if possible). It could even be hosted on your own machine (as you are the only one that will be accessing it), and the database could also live in your machine, or can be hosted and exposed to your Provider's IP Address.
4.2. Additional things you could implement
You can even go further and implement some sort of DNS management on your super admin dashboard, so that this can become a proper SaaS product where your users purchase the service, and you provide them with a domain, a new database, and an admin dashboard. All managed from your super admin dashboard.
5. My personal opinion
I believe this would be the best approach for this scenario, as I agree with the statement that "users should not be creating their own database" to use your product.
I hope this helped.
mysql_*extension is deprecated and will be removed