Page 1 of 1

Creating Database Using PHP

Posted: Fri Oct 24, 2008 11:21 am
by richardstan
I have the following function in a php file name mySQL.php

Code: Select all

 
function queryDatabase($query, $link){
        $result = mysql_query($query, $link);
        return $result;
}
 
i use include("mySQL.php") in another file called Messaging.php, then after connecting successfully, i run the script:

Code: Select all

 
    $query = "CREATE Database Messaging";
    
    $result = queryDatabase($query, $link) or die("Failed to Create Database");
 
I get the message Failed to Create Database, but is there any way in which i can check the exact error message which is returned by my queryDatabase function? i.e. doing something with $result?

Thanks
Richard.

Re: Creating Database Using PHP

Posted: Fri Oct 24, 2008 12:11 pm
by requinix
mysql_error().

Make sure that $link is a connection resource like the one returned by mysql_[p]connect.

Re: Creating Database Using PHP

Posted: Fri Oct 24, 2008 12:27 pm
by onion2k
And make sure the database user you're connect to MySQL with has been granted the CREATE privilege.

Re: Creating Database Using PHP

Posted: Fri Oct 24, 2008 1:18 pm
by Hannes2k
Hi,
in the most cases you have not the possibility to create a new database, cause the user have not the rights for creating a database.
And why would you create a new database? Normaly a database is created by the admin and your scripts should just use these databases.
A non mysql-administrativ script, e.g. a web board, shouldn't try to create his own database, it should use a provided database.