Hello, I was just wondering if I can get some simple code help. I looked pretty much everywhere and wasn't able to resolve my problem. I am simply trying to connect to my database (new one) through code. First I go to my cPanel (cPanel 11), create the Database and username I want, connect both of them with all privileges. Then I use a simple MySQL code to connect to it. <?php $db = mysql_connect("localhost","db_name","db_pass"); if (!$db){ die('Could not connect: ' . mysql_error()); }else{ echo "hello\n"; } if (mysql_query("CREATE DATABASE Persons",$db)){ echo "Database created"; }else{ echo "Error creating database: " . mysql_error(); } mysql_close($db); ?> Code (markup): For some reason It gives me an error that I don't have permission. What am I missing? I did this a few months ago and I know I am making some dumb mistake. Please help. -Thanks in advance
if (mysql_query("CREATE DATABASE Persons",$db)){ <--- here: why do you need to create another db? with cpanel, you can only add database on cpanel, unless you have root or special case set.
To be specific, your host does not allow the usernames that you create for mySQL access to use the CREATE function to make new databases. Only the username invoked by the cPanel software has this permission. This is a very common practice for hosting services. It just means that your scripts can't create new databases. You have to do that beforehand in cPanel.
Hello, I was reading MySQL tutorials and that is how they showed. I understand the cPanel allows me to make a database and username. Is it safe to assume that now I simply connect to THTA database and start making my tables, etc...? -Thanks