Page 1 of 1

MySQL Create Database

Posted: Fri Jun 17, 2005 6:27 am
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

Posted: Fri Jun 17, 2005 7:38 am
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.

Posted: Fri Jun 17, 2005 4:45 pm
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

Posted: Fri Jun 17, 2005 4:50 pm
by dnathe4th
what restriction? it just doesn't like u useing the depreciated function, thats all that error is saying

Posted: Fri Jun 17, 2005 4:59 pm
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());

Posted: Sat Jun 18, 2005 3:54 am
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..