Call to undefined function mysql_connect

后端 未结 13 742
小蘑菇
小蘑菇 2020-12-03 11:06

I just installed PHP and Apache on my home PC. When I try to call function mysql_connect I get:

fatal error: call to undefined function mysql_co         


        
相关标签:
13条回答
  • 2020-12-03 11:24

    After looking at your phpinfo() output, it appears the mysql extensions are not being loaded. I suspect you might be editing the wrong php.ini file (there might be multiple copies). Make sure you are editing the php file at C:\php\php.ini (also check to make sure there is no second copy in C:\Windows).

    Also, you should check your Apache logs for errors (should be in the \logs\ directory in your Apache install.

    If you haven't read the below, I would take a look at the comments section, because it seems like a lot of people experience quirks with setting this up. A few commenters offer solutions they used to get it working.

    http://php.net/manual/en/install.windows.extensions.php

    Another common solution seems to be to copy libmysql.dll and php_mysql.dll from c:\PHP to C:\Windows\System32.

    0 讨论(0)
  • 2020-12-03 11:27

    Background about my (similar) problem:

    I was asked to fix a PHP project, which made use of short tags. My WAMP server's PHP.ini had short_open_tag = off. In order to run the project for the first time, I modified this setting to short_open_tag = off.

    PROBLEM Surfaced: Immediately after this change, all my mysql_connect() calls failed. It threw an error

    fatal error: call to undefined function mysql_connect.

    Solution: Simply set short_open_tag = off.

    0 讨论(0)
  • 2020-12-03 11:27

    Just for future reference, copying all these extension files to Windows/System or Windows/System32 is unnecessary.

    All that is required is a copy of the php.ini file you edit in the PHP dir to copied to the root Windows dir.

    phpinfo will clearly explain the below: Configuration File (php.ini) Path C:\Windows

    Logical sense will explain that php wants to load a config located in the Windows dir. :-)

    0 讨论(0)
  • 2020-12-03 11:29

    Hi I got this error because I left out the ampersand (&) in

    ; php.ini
    error_reporting = E_ALL & ~E_DEPRECATED
    
    0 讨论(0)
  • 2020-12-03 11:31

    Check your php.ini, I'm using Apache2.2 + php 5.3. and I had the same problem and after modify the php.ini in order to set the libraries directory of PHP, it worked correctly. The problem is the default extension_dir configuration value.

    The default (and WRONG) value for my work enviroment is

    ; extension_dir="ext"
    

    without any full path and commented with a semicolon.

    There are two solution that worked fine for me.

    1.- Including this line at php.ini file

    extension_dir="X:/[PathToYourPHPDirectory]/ext
    

    Where X: is your drive letter instalation (normally C: or D: )

    2.- You can try to simply uncomment, deleting semicolon. Include the next line at php.ini file

    extension_dir="ext"
    

    Both ways worked fine for me but choose yours. Don't forget restart Apache before try again.

    I hope this help you.

    0 讨论(0)
  • 2020-12-03 11:32

    This same problem drove me nuts (Windows 10, Apache 2.4, MySql 5.7). For some reason (likely PATH related), the .dlls would not load after uncommenting the correct exension dlls and extension_dir = "ext" in php.ini. After trying numerous things, I simply changed "ext" to use the full directory path. For example. extension_dir = "c:/phpinstall/ext" and it worked.

    0 讨论(0)
提交回复
热议问题