LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Weird PHP error: Cannot create MySQL database from a function?!!? (https://www.linuxquestions.org/questions/programming-9/weird-php-error-cannot-create-mysql-database-from-a-function-487590/)

JockVSJock 09-27-2006 11:30 PM

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

Matir 09-28-2006 01:11 AM

It seems that your PHP installation can't find the mysql libraries... was it built with mysql support?

silent_cutthroat 09-28-2006 01:14 AM

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.

JockVSJock 09-28-2006 06:23 PM

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???

graemef 09-28-2006 06:47 PM

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.

JockVSJock 09-28-2006 08:46 PM

Ok, so I changed

mysql_create_db

to

mysql_query()

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

Thanks for you help!


All times are GMT -5. The time now is 07:33 PM.