mysql_query("CREATE DATABASE Question

Status
Not open for further replies.

Kenbob

New Member
Messages
18
Reaction score
0
Points
0
QUICK QUESTION FOR SOMEONE

CODE
<?php
$con = mysql_connect("localhost","kenbob_Ken","Ken");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
ERROR
Error creating database: Access denied for user 'kenbob_Ken'@'localhost' to database 'my_db'

Question: This is from an example. It is true that you have to go the the mySQL Databases to create a database. It it true you can not create it in your script or is it because this is the no-add web page thing?


Here is all the code: (it is the 2nd <?php that bombed!
<?php
$con = mysql_connect("localhost","kenbob_Wayne","Wayne");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
mysql_close($con);
?>





<?php
$con = mysql_connect("localhost","kenbob_Ken","Ken");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Create it using CPanel. The code is fine, just doesn't work too well on a shared host that doesn't give you database creation privileges :p
 

onewalrus

New Member
Messages
21
Reaction score
0
Points
0
You could go look at the "error reports", from the link in your cpanel and find some useful info there.
Could you explain more specifically what you are trying to do and how you are going about it? This will help in finding a solution.
 

Micro

Retired staff <i> (11-12-2008)</I>
Messages
1,301
Reaction score
0
Points
36
You cannot create databases thru this method, only through cPanel. Same as Dropping them, through cPanel.
 

Kenbob

New Member
Messages
18
Reaction score
0
Points
0
Thanks - made database through cpanel The example code made it look like you could make a database on the fly. It appears that if you have privledges you can. No problem......
 

rc28ally

New Member
Messages
1
Reaction score
0
Points
0
well i'm searching how i can create my database and i can't find it !!!

Someone helps me!?!?
 
Status
Not open for further replies.
Top