Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-28-2006, 12:30 AM   #1
Registered: Jan 2004
Posts: 784

Rep: Reputation: 45
Weird PHP error: Cannot create MySQL database from a function?!!?

So I'm coding up the following example

PHP Code:

mysql_connect("localhost","user","foo") or
        die (
"Check MySQL is up and running and/or the install scrpit");

//create the main database 
        or die(
//    $query_string = "Create database wiley";
//    mysql_query($query_string)
//        or die(mysql_error());

//    if(mysql_create_db("wiley"))
//    {
//        print("Database created successfully\n");
//    }
//    else
//    {
//        print("Error creating database: %s\n", mysql_error());
//    }    
    //make database an active db     
mysql_select_db ("wiley");

//create "movie" table 
$movie "CREATE TABLE movie
    movie_id int(11) not null auto_increment, 
    movie_name varchar(255) not null,
    movie_type tinyint(2) not null default 0,
    movie_year int(4) not null default 0, 
    movie_leadactor int(11) not null default 0, 
    movie_director int(11) not null default 0, 
    primary key (movie_id), 
    key movie_type (movie_type,movie_year)

$results mysql_query($movie
        or die (

//create "movietype" table 
$movietype "CREATE TABLE movietype 
        movietype_id int(11) not null auto_increment, 
        movietype_lable varchar(100) not null,
        primary key (movietype_id)

$results mysql_query($movietype
        or die(

//create "people" table 
$people "CREATE TABLE people 
    people_id int(11) not null auto_increment, 
    people_fullname varchar(255) not null,
    people_isactor tinyint(1) not null default 0, 
    people_isdirector tinyint(1) not null default 0, 
    primary key (people_id)

$results mysql_query($people)
        or die(

"Movie Database successfully created!"

When I try to run this php from the browser nothing I
use the following

php -a createmovie.php

and I get this output

cmmiller@probot:~/php$ php -a createmovie.php
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/' - /usr/local/lib/php/ cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/' - /usr/local/lib/php/ cannot open shared object file: No such file or directory in Unknown on line 0
Interactive mode enabled

PHP Fatal error:  Call to undefined function mysql_create_db() in /home/cmmiller/php/createmovie.php on line 8
If you look at the last line, it is telling me that the function

mysql_create_db() is undefined???

I check here

and it says that it is I'm really confused as to what is going on?!!?

So php experts, let me know what you think...


Last edited by JockVSJock; 09-28-2006 at 12:31 AM.
Old 09-28-2006, 02:11 AM   #2
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 122Reputation: 122
It seems that your PHP installation can't find the mysql libraries... was it built with mysql support?
Old 09-28-2006, 02:14 AM   #3
LQ Newbie
Registered: Nov 2005
Distribution: Arch
Posts: 27

Rep: Reputation: 15
Your PHP is not build with MySQL support. Since PHP5 I think, it's optional, so you have to rebuild your PHP or install package with the MySQL module build. But check out the Apache module it may have the MySQL functions available.
Old 09-28-2006, 07:23 PM   #4
Registered: Jan 2004
Posts: 784

Original Poster
Rep: Reputation: 45
Here is the output from my phpinfo.php about mysql


MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => 4.1.21
MYSQL_SOCKET => /var/run/mysql/mysql.sock
MYSQL_INCLUDE => -I/usr/include/mysql
MYSQL_LIBS => -L/usr/lib -lmysqlclient

Directive => Local Value => Master Value
mysql.allow_persistent => On => On
mysql.connect_timeout => 60 => 60
mysql.default_host => no value => no value
mysql.default_password => no value => no value
mysql.default_port => no value => no value
mysql.default_socket => no value => no value
mysql.default_user => no value => no value
mysql.max_links => Unlimited => Unlimited
mysql.max_persistent => Unlimited => Unlimited
mysql.trace_mode => Off => Off
and I'm running php5, and have those modules in my http.conf
file, but someone was saying I have to compile in MySQL???
Old 09-28-2006, 07:47 PM   #5
Senior Member
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Taken from the php document link that you posted...

Note: This function will not be available if the MySQL extension was built against a MySQL 4.x client library.

The recommendation in the documentation is:

The function mysql_create_db() is deprecated. It is preferable to use mysql_query() to issue a sql CREATE DATABASE statement instead.
Old 09-28-2006, 09:46 PM   #6
Registered: Jan 2004
Posts: 784

Original Poster
Rep: Reputation: 45
Ok, so I changed




...and was able to create the database and tables successfully.

Thanks for you help!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Php search mysql database jamesjoy Programming 4 12-02-2005 08:28 AM
PHP-MySQL Weird Error Fordor Slackware 2 02-24-2005 01:01 PM
How to create Database in mysql irfanhab Linux - General 1 12-16-2004 07:37 PM
MySQL - command - create user/single database dmedici Linux - Software 3 06-21-2004 04:17 PM
query DNS and create mysql database nabil Programming 0 01-18-2002 05:42 AM

All times are GMT -5. The time now is 03:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration