Can you create MySql databases using php on a local server. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can you create MySql databases using php on a local server.

I've tried and for the life of me i cant get it to work. I cant remember off the top of my head but my code is something like $sql = "CREATE DATABASE MyDatabase"; It never works. I have to go into MyPhpAdmin and create them that way.

19th Apr 2017, 2:50 AM
Erica Perkins
Erica Perkins - avatar
4 Answers
+ 11
Use localhost and try. Search on Youtube, how to run sql query on localhost using XAMPP
19th Apr 2017, 3:32 AM
Sachin Artani
Sachin Artani - avatar
+ 7
yes,. but you should install and configure MySQL also.
19th Apr 2017, 3:06 AM
Nithin
Nithin - avatar
+ 2
Your code should work, syntax is right. Maybe you forgot to set up user restrictions for your php connection if you do not use root user or you do not execute query from PHP properly.
19th Apr 2017, 4:12 AM
Jeth
Jeth - avatar
0
try this and tell me the result: $sql="CREAT DATABASE IF NOT EXISTS MyDatabase";
20th Apr 2017, 8:19 PM
Elghozi Nasreddine
Elghozi Nasreddine - avatar