【问题标题】:PHP7 can't connect to MySQLPHP7无法连接到MySQL
【发布时间】:2017-02-05 12:00:41
【问题描述】:

以下代码在 PHP5 和 MySQL5.6 上运行。在 Kubuntu 和 Windows 下。在这种特殊情况下,我试图在 Kubuntu 16.04 PHP7 和 MySQL5.7 下运行它。无法建立与数据库的连接。没有错误消息,执行以连接到 base 的行结束,结果是代码中的 report_before 被键入,但 report_after 不是。

<?php

echo "<form id='login' action='' method='POST' accept-charset='UTF-8'>";
echo "<input type='password' name='password' id='password' maxlength='50'>";
echo "<input type='submit' name='OK' value='OK'>";

if (isset($_POST["password"]))
{
    if($_POST["password"] == '1234')
    {
        echo "rep_before";
        $link = mysql_connect('localhost:3306', 'acs', 'sesame');
        echo "rep_after;
        if ($link) 
        {
            session_start();
            header('Location: main_page.php');
        }
    } 

}

【问题讨论】:

    标签: mysql php-7


    【解决方案1】:

    问题来了:

     $link = mysql_connect('localhost:3306', 'acs', 'sesame');
    

    http://php.net/manual/en/intro.mysql.php

    此扩展自 PHP 5.5.0 起已弃用,并已被删除 PHP 7.0.0.

    使用 mysqli,几乎相同,但您必须升级所有代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-23
      • 2016-08-06
      • 2018-05-02
      • 2014-04-09
      • 2011-03-14
      相关资源
      最近更新 更多