MySQL Create Database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
roland E W Mucke
Forum Newbie
Posts: 4
Joined: Thu Jun 16, 2005 2:56 pm
Location: New Zealand

MySQL Create Database

Post by roland E W Mucke »

Hi there,

I use different codes for connecting, create tables etc.etc. and everything seems to work. But unfortunatly I have this one problem not to be able to create a DB with PhP. I have to create the DB in a prompt and than fine, but not the Create DB with PhP ???.

My error message:

Code: Select all

Fatal error: Call to undefined function mysql_create_db()
I use different codes here as well i.e. PhP web site, but this is the easy one still no luck:

Code: Select all

<?
$link = mysql_connect("localhost","root", "Password");
if (! $link)
die("Couldn't connect to MySQL");
//create database
mysql_create_db("mydatabase")or die("Create Error: ".mysql_error());
mysql_close($link);
?>
Thanks for any help: aktell
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

straight from PHP documentation
For downwards compatibility mysql_createdb() can also be used. This is deprecated, however.

Not: The function mysql_create_db() is deprecated. It is preferable to use mysql_query() to issue a SQL CREATE DATABASE Statement instead.

Warning
This function will not be available if the MySQL extension was built against a MySQL 4.x client library.
Also, don't rely on this as a solution as it is very commonly not possible to create databases due to restrictions.
roland E W Mucke
Forum Newbie
Posts: 4
Joined: Thu Jun 16, 2005 2:56 pm
Location: New Zealand

Post by roland E W Mucke »

Hi there,

YES, you are right I tried this one already before and with no luck so ??? I’m still not better off. Anybody would not know by any chance how to get over the restriction as this is my only problem.

Thanks aktell
dnathe4th
Forum Newbie
Posts: 16
Joined: Fri Jun 17, 2005 2:01 pm

Post by dnathe4th »

what restriction? it just doesn't like u useing the depreciated function, thats all that error is saying
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Dude it's probably easier (and surely forwards and backwards compatible) just to do:

Code: Select all

mysql_query("CREATE DATABASE `foobar`") or die (mysql_error());
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

If this is in a hosting environment rather than on your test machine I imagine the mysql user you're connecting with won't have the CREATE priviledge. At least, if it's been set up by anyone with half a brain it won't have..
Post Reply