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
https://forums.phpfreaks.com/topic/11765-create-database-mysql-just-wont-work/
Share on other sites

try

[code]$cnx = mysql_connect('localhost', '*****', '*******');
mysql_select_db('mysql');

$sql = "SELECT * FROM user WHERE user = 'myusername'";
$res = mysql_query($sql);
$row = mysql_fetch_assoc($res);
echo '<pre>', print_r($row, true), '</pre>';[/code]
[!--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]
[!--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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.