Fatal error: Call to undefined function mysql_connect()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Julian Bowler
    New Member
    • Dec 2008
    • 28

    #1

    Fatal error: Call to undefined function mysql_connect()

    Please can some one help with my problem; I am running Apache web server on my lap top, plus a mysql server and php. The version of php currently installed is 5.2.5.
    when i write some php to connect to my mysql database server instead of it connecting i get :
    Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\h tdocs\chephrenr epairs\dataentr yprocess.php on line 16.

    question 1 is this:
    Is this happening because the version of php i have installed has no support for mysql bundled with it?

    Question 2: Are there some versions of php 5 that have no support for mysql at all because it was removed by the php writters and if so which versions of php 5 do have mysql support built in to them that works properly?

    I have looked on this forum and found that someone said that mysql support was removed in php 5, but it sdoes not say which version of php 5 it was removed from, neither does it hint as what to do to get php communicating twith the local mysql server??

    if questions 1 and 2 have been answered in anther thread on this forum then please where???
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    short answers:
    1. probably

    2. that depends on the distributors of the according PHP build. I think the PHP 5 source code has general support, may it be enabled by default or not.

    long answers:
    I'm not aware that MySQL support has been cancelled on PHP 5. nevertheless, you can get proof of that by looking at the phpinfo() page. just on top should be the configure commands (the ones that tell you with what preferences your PHP was build). if you can't find the option '--with-mysql=/$path' ($path is the path to PHP's mysql files)(or alternatively there is the option '--without-mysql') what I suspect from the error message, then you have to either get another PHP build or you have to build it yourself...

    to avoid reinstalling you can try the MDB2 PEAR package (at PEAR :: The PHP Extension and Application Repository)

    regards

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Julian.

      Check out this page for more information:
      PHP: Installation - Manual

      Comment

      • Julian Bowler
        New Member
        • Dec 2008
        • 28

        #4
        thanks to the two people that have replied, pbmods and dormilich!
        I have ran phpinf() and looked at the resulting page, Under Apache environment is says in the PATH Section
        C:\Program Files\PHP\;C:\W INDOWS\system32 ;C:\WINDOWS;C:\ WINDOWS\System3 2\Wbem;C:\Progr am Files\MySQL\MyS QL Server 4.1\bin;"C:\Pro gram Files\Symantec\ Norton Ghost 2003\"
        also in the environment section and th php variable section there is MySQL mentioned!
        So i do not know what this means unfortunately, I have managed to download some other versions of php 5, so I am going to remove my present version of php completely and leave the configuration file for Apache alone and then install a different version of php on the laptop?
        The question becomes which version of php will definitely have Mysql support bundled in it ?? I do not know, is there a place where i can simply answer this question please?? thanks inadvance Julian

        Comment

        • Julian Bowler
          New Member
          • Dec 2008
          • 28

          #5
          Before I do try what i said in my previous post about trying a different version of php 5 i am going to follow the advice that pbmods said which essentially points to some helpful information on installing php I am essentially going to try to manually reconfigure php to recognise the mysql local server correctly and my results will be posted latter on here in this thread julian

          Comment

          • Julian Bowler
            New Member
            • Dec 2008
            • 28

            #6
            I Read on the php site that in order for mysql support to be working that the file php-mysql.dll must be enabled inside the php.ini configuration file. inside the php.ini file i can find no reference to php-mysql.dll

            Also, there is no file with the name php-mysql.dll inside the php directory anywhere at all...... does this mean then that php 5.2.5 simply does not have any MySQL Support??? ??

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by Julian Bowler
              Also, there is no file with the name php-mysql.dll inside the php directory anywhere at all......
              Maybe it's not in the PHP folder but the MySQL folder, try searching all folders of the PATH variable. the $PATH section clearly denotes, that MySQL can be used (otherwise, why putting the MySQL path in?).

              Alas, since I run PHP on a Mac I can only guess further.....

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8
                in a windows installation, all the extensions goes to a directory named <php-installtion-path>/ext

                there you need to add this line in php.ini to load the extensions from that dir. make sure it is already there.
                Code:
                ; Directory in which the loadable extensions (modules) reside.
                extension_dir ="C:\Program Files\PHP\ext"
                If the php_mysql.dll is available on the /ext dir, you can load it to the php environment like this.
                Code:
                [PHP_MYSQL]
                extension=php_mysql.dll
                If you have used a .msi file for the installation, just try to reinstall it and select a custom installation from there. you can then enable relevant extensions from "extras" menu of the installer.

                Comment

                • Julian Bowler
                  New Member
                  • Dec 2008
                  • 28

                  #9
                  many thanks for reply from ak1dnar. i have tried a few things that did not work, not i hasten to add. the thing you wrote about in you post to this thread..
                  yesterday I removed the old folder containing php 5.2.5, and it seems that removing the php directory is the way to uninstall php!!! Then i found a CD rom in a book called Sams Teach Yourself PHP, MySQL and Apache. This CD has on it PHP 5.0.2 in fact,and also a program that unzips all the files to C:/PHP5. so i did that.
                  than i found the file inside this directory called php.ini-recommended and renamed it php.ini.
                  then i copied this file called php.ini into the windows directory.
                  then i copied the file php5ts.dll into C:\windows\syst em. then i went to the apache configuration file called httpd.conf and did some editing, here is what i did;
                  at the end of the section where you see lots of lines saying Loadmodule..... ..
                  I added:
                  LoadModule php5-module c:/php5/php5apache2.dll
                  this line above must be exactly as is above otherwise Apache will not be able to start
                  then i found section starting
                  #
                  # AddType allows you to add or overide

                  and i added this line:
                  AddType application /x-httpd.php .php .phtml .html .php3
                  then i saved the apache configuration file and then restarted apache
                  This seems to have worked..... but i am still trying to understand exactly why??
                  I am putting up some stuff About this at my web site which will appear at:
                  chephrenrepairs .com - Home
                  i do want to understand more about how php and mysql interact, it seems to me that some php versions do simply have inbuilt MySQL support and some do not have this inbuilt???

                  Comment

                  • Julian Bowler
                    New Member
                    • Dec 2008
                    • 28

                    #10
                    ok... i am looking at your post ak1dnar, and i notice that with my new installation of php which is as i say version 5.0.2, inside the directory C:\PHP5 there is another directory called /ext.
                    Inside this directory there are lots of .dll files and amongst them there is php_mysql.dll and php_mysqli.dll
                    Also i am looking inside the new php.ini file that now resides inside C:\windows.
                    and in this file i find these lines:
                    ;extension=php_ msql.dll
                    ;extension=php_ mysql.dll

                    i find these lines in the part of the file where it starts:
                    ;Windows Extensions
                    ;Note that ODBC support is built in, so no dll is needed for it.
                    ;


                    is it correct that if lines in php.ini start with a ; that they are in fact turned into comments and hence ignored???
                    therefore both these lines will be ignored, so i do not at the moment understand, what is it that actually allows php to be able to run successfully code to connect to a mysql server along with of course lots of other mysql type functions ???

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      Originally posted by Julian Bowler
                      is it correct that if lines in php.ini start with a ; that they are in fact turned into comments and hence ignored???
                      yes, that's correct.

                      Comment

                      • Julian Bowler
                        New Member
                        • Dec 2008
                        • 28

                        #12
                        when i said in the previous but one posts that what i did worked, i.e. got php to run mysql functions correctly, well that's not true because when i run the correct php to connect to the local MySQL Server, i did not get the fatel error message suggesting that the function mysql_connect() has failed to work , instead I get just a blank page, with no writing in it at all??!
                        so what does that mean? does it mean that any of the php is working at all/ I am going to continue to try to figger this out, and what i find out will be in this thread on this forum i hope shortly, watch this space...!!!!???

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          that looks like a PHP runtime error (e.g. a defect library). try to figure out which function may cause this (e.g. if a DB library is defect, php code without DB functions should work fine, something like that)

                          Comment

                          • Julian Bowler
                            New Member
                            • Dec 2008
                            • 28

                            #14
                            if i run a little php to echo some text to the screen that works, but what about the function $conn = mysql_connect(" localhost","USE R_NAME","PASSWO RD");
                            as we know there a lots of mysql php functions, but the one i am using simply is designed to make a connection to a database. it should either work or not work?
                            I need to look at whether error reporting is switched on or off, and what level of error reporting is enabled and possibly other things also. i need to also test to see if some other php functions not related to MySQL work ok. i will do some testing...
                            Last edited by ak1dnar; Dec 31 '08, 03:42 AM.

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #15
                              Originally posted by Julian Bowler
                              as we know there a lots of mysql php functions, but the one i am using simply is designed to make a connection to a database. it should either work or not work?
                              basicly yes. but the mysql library may be corrupted (then you get no output at all (not even error messages)) or there may be an error in the php.ini....

                              regards

                              one more thing: never ever post passwords (use something generic like "password")

                              Comment

                              Working...