LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 09-27-2006, 11:30 PM   #1
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420
Blog Entries: 4

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


So I'm coding up the following example

PHP Code:

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

    
//create the main database 
    
mysql_create_db("wiley")
        or die(
mysql_error());
        
//    $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)
    )"
;
    
//TYPE=MyISAM AUTO_INCREMENT=4 ";

    
$results mysql_query($movie
        or die (
mysql_error()); 

        
    
//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)
        )"
;
        
//TYPE=MyISAM AUTO_INCREMENT=9" ;

    
$results mysql_query($movietype
        or die(
mysql_error());

    
//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)
    )"
;
    
//TYPE=MyISAM AUTO_INCREMENT=7";

    
$results mysql_query($people)
        or die(
mysql_error());

    echo 
"Movie Database successfully created!"

?>
When I try to run this php from the browser nothing happens...so I
use the following

php -a createmovie.php

and I get this output

Code:
cmmiller@probot:~/php$ php -a createmovie.php
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/mysql.so' - /usr/local/lib/php/mysql.so: 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/gettext.so' - /usr/local/lib/php/gettext.so: 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

http://us2.php.net/mysql_create_db

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

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

thanks

Last edited by JockVSJock; 09-27-2006 at 11:31 PM.
 
Old 09-28-2006, 01:11 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
It seems that your PHP installation can't find the mysql libraries... was it built with mysql support?
 
Old 09-28-2006, 01:14 AM   #3
silent_cutthroat
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, 06:23 PM   #4
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Here is the output from my phpinfo.php about mysql

Code:
mysql

MySQL Support => enabled
Active Persistent Links => 0
Active Links => 0
Client API version => 4.1.21
MYSQL_MODULE_TYPE => external
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, 06:47 PM   #5
graemef
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, 08:46 PM   #6
JockVSJock
Senior Member
 
Registered: Jan 2004
Posts: 1,420

Original Poster
Blog Entries: 4

Rep: Reputation: 164Reputation: 164
Ok, so I changed

mysql_create_db

to

mysql_query()

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

Thanks for you help!
 
  


Reply



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 07:28 AM
PHP-MySQL Weird Error Fordor Slackware 2 02-24-2005 12:01 PM
How to create Database in mysql irfanhab Linux - General 1 12-16-2004 06:37 PM
MySQL - command - create user/single database dmedici Linux - Software 3 06-21-2004 03:17 PM
query DNS and create mysql database nabil Programming 0 01-18-2002 04:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:09 PM.

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