Jump to content


Photo

CREATE DATABASE "mysql" just wont work


  • Please log in to reply
4 replies to this topic

#1 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 12 June 2006 - 06:18 AM

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
The best way to learn
is to ask you lot........

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 12 June 2006 - 10:59 AM

try

$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>';

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 d_barszczak

d_barszczak
  • Members
  • PipPipPip
  • Advanced Member
  • 188 posts
  • LocationBradford - UK

Posted 12 June 2006 - 11:03 AM

[!--quoteo(post=382764:date=Jun 12 2006, 07:18 AM:name=thehigherentity)--][div class=\'quotetop\']QUOTE(thehigherentity @ Jun 12 2006, 07:18 AM) View Post[/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.


<?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());
?>

When all else fails - Try reading the manual.

Integrated IT Systems Ltd


#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 12 June 2006 - 02:16 PM

Chances are, your webhosting company doesn't let you to access the "mysql" database, let alone modify it.
~ D Kuang

#5 thehigherentity

thehigherentity
  • Members
  • PipPipPip
  • Advanced Member
  • 49 posts

Posted 12 June 2006 - 11:28 PM

[!--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) View Post[/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.
<?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());
?>
[/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
The best way to learn
is to ask you lot........




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users