Jump to content

CREATE DATABASE "mysql" just wont work


thehigherentity

Recommended Posts

im trying to get better with mysql and at the moment im trying to create a new database with php code, however it just wont work i have looked all over and read just about everything i can find about creating a db

according to the admin section of my server i Im using
PHP version 5.0.5
and
MySQL version 4.1.19

and i have the rights to create and drop databases as well as change the tables etc

I first tried myaql_create_db befor i found out this will not work

I believe the right code is ment to be

mysql_query("CREATE DATABASE my_db")

however this wont work eather, all i get is an error saying somthing like

Access denied for user 'username'@'localhost' to database 'my_db'

but i can connect and read the other already existing databases?

is there somthing im missing here i was under the impresion mysql was easy to connect to

is there anyway i can test my privaliges and see if its somthing like that? or any other ideas would be great
Link to comment
Share on other sites

[!--quoteo(post=382764:date=Jun 12 2006, 07:18 AM:name=thehigherentity)--][div class=\'quotetop\']QUOTE(thehigherentity @ Jun 12 2006, 07:18 AM) [snapback]382764[/snapback][/div][div class=\'quotemain\'][!--quotec--]according to the admin section of my server i Im using
PHP version 5.0.5
and
MySQL version 4.1.19
[/quote]

Guessing by the above you are using a hosting company as apposed to running your own local web server.

If this is the case a lot of hosting companies (Including Mine) will allow you to create your own Databases but only through their admin interface. I have a test server which i use and the following code worked for me on that server but not on my ISP Server.


[code]
<?php

$query = "CREATE DATABASE my_db";

$user = "username";
$pass = "password";
$host = "localhost";

mysql_connect($host, $user, $pass) or die(mysql_error());

mysql_query($query) or die(mysql_error());
?>
[/code]
Link to comment
Share on other sites

[!--quoteo(post=382793:date=Jun 12 2006, 06:03 AM:name=scripts2go.co.uk)--][div class=\'quotetop\']QUOTE(scripts2go.co.uk @ Jun 12 2006, 06:03 AM) [snapback]382793[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Guessing by the above you are using a hosting company as apposed to running your own local web server.

If this is the case a lot of hosting companies (Including Mine) will allow you to create your own Databases but only through their admin interface. I have a test server which i use and the following code worked for me on that server but not on my ISP Server.
[code]
<?php

$query = "CREATE DATABASE my_db";

$user = "username";
$pass = "password";
$host = "localhost";

mysql_connect($host, $user, $pass) or die(mysql_error());

mysql_query($query) or die(mysql_error());
?>
[/code]
[/quote]

I think you could be right, I have created a db through the admin area and I have managed to create the tables etc with code so it seems its the server host company thats blocking my code from making the db.

but never mind, now i just have to get my head round getting the data into the database lol
Im sure i will be posting again soon!

thanks for your help
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.