Page 1 of 1

creating new MySQL databases with php?

Posted: Sat Jan 07, 2006 9:44 am
by hanzo
Hello,

I know you can create a Mysql database with PHP this way:

Code: Select all

$query  = "CREATE DATABASE phpcake";
$result = mysql_query($query);
But how do I know what the username and password for the database are or how can I set those data?

Thanks

Posted: Sat Jan 07, 2006 10:17 am
by Jenk
in exactly the same way..

Code: Select all

<?php

$sql = "SET PASSWORD FOR 'user'@'domain' = OLD PASSWORD('new pass')"; 

mysql_query($sql) or die(mysql_error());

?>

Posted: Sat Jan 07, 2006 10:24 am
by timvw
I don't like the oldpassword :)

Code: Select all

grant all on databasename.* to 'user'@'localhost' identified by 'hispassword';

Posted: Sat Jan 07, 2006 10:31 am
by Jenk
PHP does though :P

re: "Client protocol blah blah error"

Posted: Sat Jan 07, 2006 10:37 am
by timvw
time to teach it some manners.. :)

Posted: Sat Jan 07, 2006 10:53 am
by hanzo
timvw wrote:I don't like the oldpassword :)

Code: Select all

grant all on databasename.* to 'user'@'localhost' identified by 'hispassword';
do I have to create a new user first or can it be a new one in the code?

Posted: Sat Jan 07, 2006 11:06 am
by Gambler
granting creates users by itself.

Posted: Sat Jan 07, 2006 11:06 am
by hanzo
thanks :)

Posted: Sat Jan 07, 2006 11:31 am
by hanzo
When I try to create a database I get this :(
Access denied for user 'hanzo_databases'@'localhost' to database 'hanzo_mydgd'
The login I'm using works well for other queries.

Posted: Sat Jan 07, 2006 12:31 pm
by Chris Corbyn
You don't have permission to create databases then.... is this shared hosting?

It's a pain but if you're limited to one or two databases, using prefixes on your table names can be a clean(ish) separation.

Posted: Sun Jan 08, 2006 7:49 am
by hanzo
It's reseller hosting with a directadmin control panel

I've got unlimited databases. Shall I contact the admin about it?