Creating Database Using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
richardstan
Forum Newbie
Posts: 3
Joined: Thu Oct 23, 2008 12:03 pm

Creating Database Using PHP

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Creating Database Using PHP

Post by requinix »

mysql_error().

Make sure that $link is a connection resource like the one returned by mysql_[p]connect.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Creating Database Using PHP

Post by onion2k »

And make sure the database user you're connect to MySQL with has been granted the CREATE privilege.
Hannes2k
Forum Contributor
Posts: 102
Joined: Fri Oct 24, 2008 12:22 pm

Re: Creating Database Using PHP

Post 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.
Post Reply