简体   繁体   中英

Fatal error: Call to undefined function mysql_connect()

I am trying to connect to a database that I created using MAMP. This is my code:

<?php
    $link = mysql_connect("localhost", "root", "pw", "db");
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    echo 'Connected successfully';
    mysql_close($link);
?>

I am getting this error

Fatal error: Call to undefined function mysql_connect()

I tried echo phpinfo(); to check my path and make sure that I have mySQL which I do.

Path => C: \ProgramData\ Oracle\ Java\ javapath;
C: \iverilog\ samples > ;
C: \Windows;
C: \Windows\ System32\ Wbem;
C: \Windows\ System32\ WindowsPowerShell\ v1 .0\;
C: \Users\ naomi\.dnx\ bin;
C: \Program Files\ Microsoft DNX\ Dnvm\;
C: \Program Files\ Microsoft SQL Server\ 130\ Tools\ Binn\;
C: \iverilog\ samples > ;
C: \Program Files(x86)\ Windows Kits\ 8.1\ Windows Performance Toolkit\;
C: \Program Files\ MySQL\ MySQL Utilities 1.6\;
C: \Users\ naomi\ Downloads\ php - 5.6 .30 - nts - Win32 - VC11 - x86

I looked in the folder php-5.6.30-nts-Win32-VC11-x86 to see if sql is in there too. this is what it gives me php_sqlite3.dll, php_pdo_sqlite.dll

Please help!

可能的答案是您正在使用PHP 7打包的MAMP版本。mysql_connect已被弃用一段时间,并已从PHP 7版本中删除。请使用mysqli_connect( https://secure.php.net/manual/ zh_cn / function.mysqli-connect.php )。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM