I want to create a class which uses PDO to interact with MySQL. Can I create a new MySQL table using PDO?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, you can.
The
dsnpart, which is the first parameter of the PDO constructor, does not have to have a database name. You can simply usemysql:host=localhost. Then, given you have the right privilege, you can use regular SQL commands to create a database and users, etc.Following is an example from an install.php file. It logs in with root, create a database, a user, and grant the user all privilege to the new created database: