Page 1 of 7 123 ... LastLast
Results 1 to 10 of 65
  1. #1
    Join Date
    Mar 2002
    Location
    Denmark
    Posts
    684

    Important!! PHP 5 and MySQL "Fatal error: Call to undefined function ...." A Guide...

    If you have followed the PHP/MySQL VTMs and you get "Fatal error: Call to undefined function ..." then you have probably downloaded the newest version of PHP (probably version 5) which does not include support for MySQL as default. What this means is that you need to enable MySQL support...

    ***Please note: This guide is old and slightly out of date, if you are hacing trouble have a read through some of the follow-up comments***

    Logan and Buzz have created a new updated version of the first VTM in the series called The Developers Corner. Now before you go and say that the series is only for member sponsors, the first issue is free... They explain how to set up PHP to support MySQL with PHP 5.

    But in case you cannot download the VTM here is a "quick" guide to installing and setting up PHP to support MySQL... I am assuming that you are using a Windows machine... =)

    STEP #1:
    Download guide:
    -MySQL: download the new version of MySQL, this would be version 5, although it is a little overkill to use this version(search this forum for possible reasons why), but anyway...
    -Apache: download version 2, get the Win32 Binary (MSI Installer) the install is easier... =)
    -PHP: get version 5.1.1, get the zip package

    STEP #2:
    Installation guide:
    2.1: Install Apache first.
    -Install dir: C:\ApacheGroup\Apache2\
    -choose port 80, should be the default, but just to make sure, if you have another webserver installed choose a different port to avoid conflicts
    -if you wish to install apache as a service, do this... =)
    -Once the installation is complete, make sure that apache is started, and go to http://localhost/
    -If apache is installed and started you should see a very nice apache default welcome page. =)

    2.2: PHP install next.
    -unzip the contents to C:\php\
    -copy php.ini-recommended and rename the file to php.ini

    2.3: MySQL is next.
    -start the msi file
    -if you wish you can install mysql as a service, up to you.
    -choose a root password, don't leave it blank, remember the password we will need it later...
    -port 3306, should be the default, if you have previously installed MySQL you will need to choose a different port so that the two don't conflict... =) or uninstall the old version...
    -during configuration it is best to choose development as less resources are used on your machine

    STEP #3:
    install should be done now... Next we need to glue all the parts together...

    3.1: Apache and PHP
    open http.conf from C:\ApacheGroup\Apache2\conf\
    go to the bottom(for example), and add these lines:

    LoadModule php5_module "c:/php/php5apache2.dll"
    AddType application/x-httpd-php .php

    PHPIniDir "C:/php"

    Okay LoadModule is the path to the DLL which "binds" php and apache together, so make sure that this file actually is in c:/php/ do a quick search in the dir to make sure..
    Next line, AddType, associates the extension .php to be handled by the PHP engine...
    The last line, PHPIniDir specifies the location of the php.ini file, which was why we did not move it... =)

    Since this guide was initially created there have been a few people who have had trouble with using the PHPIniDir parameter. If you discover that even after making the changes described below to php.ini and you still cannot get it to work I suggest dropping the PHPIniDir parameter and place the php.ini file in c:\windows. Now the rest of the steps can be followed without further modification.


    3.2: PHP and MySQL
    Next we need to configure PHP is recognize MySQL function calls.
    open php.ini from c:/php (or c:\windows)
    search for php_mysql.dll should be around line 635, but don't quote me on that as they may have changed it from the version of 5 I am using...
    remove the ; infront of the line extension=php_mysql.dll
    Search for MySQL you should see some configuration settings for MySQL, although no changes need to be made here at this time, have a look at the settings... one of the settings you can change is the deafult port which php uses to connect to MySQL, this is handy because if you choose to install MySQL using a different port than the default 3306(the default) you need to specify this new port number in our PHP scripts, which means that when you move your scripts from one server to another you need to change the port number in the scripts, using this setting you can change which port php uses and you don't need to specify a port number in your scripts which means that moving from one server to another requires no modification to the port number within a script... =)

    still there? okay we are nearly there...

    STEP #4:
    Next you need to set up a MySQL user, the easiest way is to open up the mysql Command Prompt...(Start > Run > cmd)
    navigate to your MySQL install dir then to the bin folder(for example C:\MySQL\bin)...
    type mysqld -u root --password
    now type the root password you created during install process...
    enter this SQL statement:
    GRANT ALL ON *.* to php@'localhost' IDENTIFIED BY 's3cret';

    this creates a user by the name of php with paswword s3cret which can only access the database from localhost...
    the *.* specifices <database>.<table> so *.* means access to all databases and tables, 3dbuzz.* would give access to all tables in database 3dbuzz

    notice how the password is in plain text? well mysql will "encrypt" the password for you using the PASWORD MySQL function...
    http://dev.mysql.com/doc/refman/5.0/en/grant.html

    Now you can either restart MySQL server or enter
    FLUSH PRIVILEGES;

    which will instruct the server to re-read the privileges table...

    Please note that all this is plain SQL, and you are not required to carry out these commands(or SQL queries) from the mysqld command line program. If you have a GUI program that you are used to using to create users and modify the user rights then by all means use that instead of firing these sql queries. Whatever makesit easier for you.
    With MySQL 5 you can download some very handy GUI tools:
    www.mysql.com/products/tools/
    download site : http://dev.mysql.com/downloads/gui-tools/5.0.html
    The MySQL Administrator tool allows you to, as the name suggests, administer MySQL server instances. There is one little trick, MySQL have changed their terminology slightly to fit in with the "standard" Database world. What MySQL used to call a "database" is now called a "schema". They are the same thing, and the complete as in some tabs and menus they still use the term database instead of shcema. There is nothing wrong with it, but it can get a little confusing. If you just keep in mind that the terms schema and database mean the same thing.
    I highly recommend that you download these tools and use them instead of the command line tool as it is a lot easier to use.
    ***This term change does not change how you use MySQL***

    Alright, you made it! if you run into problems or get errors post how far you got(the step number) where you ran into problems or post the exact error you get and the code so that the friendly people here at 3Dbuzz can help you get to the bottomof the problem... Also post the version numbers of PHP/Apache/MySQL if they are different from the ones used here. =)

    Also as a final note, if you find all of this confusing an just want to try php I suggest using a WAMP(windows, apache, mysql, php) installer, which basically does everything for you. =)
    Yes i know I should have told you this at the start, but I believe that by doing the configuration manually you learn oh so much more.
    Last edited by nchris; 04-13-2007 at 02:47 PM.
    ~Chris

  2. #2
    Join Date
    Jan 2006
    Location
    Trinidad & Tobago
    Posts
    2
    or if you're a n00b like myself you can just install the versions following the instructions in the VTM's

  3. #3
    Join Date
    Mar 2002
    Location
    Denmark
    Posts
    684
    ahhh if only it was that simple... a quick search will reveal that the newer version of PHP are used and not the versions in the VTMs...
    which is why I made the post in the first place and asked for it to become a sticky thread... =)
    But yes downloading the versions used in the VTM is a good solution as well...
    ~Chris

  4. #4
    Join Date
    Jan 2006
    Location
    Trinidad & Tobago
    Posts
    2
    I think the instuctions in the VTM's are best suited for people who are totally new to PHP / MySQL. Kind of like being spoon fed everything instead of hunting down other instuctions for installing different versions.

    But great post btw.

  5. #5
    Join Date
    Jun 2005
    Location
    Hamburg, GERMANY
    Posts
    20

    Heeeeelp

    first thank you for writting such a tutorial...

    but i have a big problem now: I followed your steps but i cant get PHP running.
    I added to the Apache httpd.conf file your 3 lines and restartet Apache. Then i wanted to test if it worked and i made a little .php file
    actully i just made this:

    <?
    echo phpinfo();
    ?>


    but when i try to load it into my browser (over "http://localhost/test.php") it wont work. It just displays a blank white screen...
    I have Apache 2.0.55 and i unzipped PHP-5.1.1-Win32 to the folder: "c:\php\"

    any ideas?

    EDIT: okay i made it..... instead of using your 3 lines, nChris, i looked on other websites and found this:

    LoadModule php5_module "c:/php/php5apache2.dll"
    AddType application/x-httpd-php .php

    so i entered it, saved the httpd.conf, restarted the server and for some strange reasons it displayed me the PHP info site >>LOL<<


    Okay i ran into another problem... i installed MySQL-5.0.18-win32 and i can accsess mysql through the command prompt. can create databases and so on...

    now i wanted to make the whole stuff with "phpMyAdmin" but when i load the "index.php" in my browser following errormessage appears:

    Fatal error: Call to undefined function mysql_get_client_info() in C:\localhost\phpMyAdmin\libraries\defines.lib.php on line 47


    can someone help me?
    Last edited by Ironcheese; 01-08-2006 at 02:58 PM.

  6. #6
    Join Date
    Mar 2002
    Location
    Denmark
    Posts
    684
    uhm... okay about the 3 lines... the frist two lines are exactly the same, but if it works oh well... maybe the PHP inidiris not needed.. oh well...

    about the phpMyAdmin thing.. are you sure you followed the steps to get MySQL working with PHP? Step 3.2
    Have you tried creating your own little MySQL PHP script?
    ~Chris

  7. #7
    Join Date
    Jun 2005
    Location
    Hamburg, GERMANY
    Posts
    20
    okay i made a little test script. Actully i made the connection script from the PHP VTM "Intergation".

    On my webspace it worked very well. But on my computer im still getting this error message:

    Call to undefined function mysql_connect()

    it seems that PHP dont recognize mysql.... and i really dont know why. I change the line in the PHP.ini do i need to do additional modifications?

  8. #8
    Join Date
    Mar 2002
    Location
    Denmark
    Posts
    684
    restart the server, either apache or your machine....
    ~Chris

  9. #9
    Join Date
    Jun 2005
    Location
    Hamburg, GERMANY
    Posts
    20
    done... still wont work

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    4
    i have the same problem (i'm using windows xp apache 2.0.55 php 5.1.2 and mysql 5.0)
    Last edited by plomplot; 01-23-2006 at 10:57 AM.

Page 1 of 7 123 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •