PHP7无法连接到MySQL [英] PHP7 can't connect to MySQL

查看:299
本文介绍了PHP7无法连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The following code had worked on PHP5 and MySQL5.6. Under Kubuntu and Windows. In this particular case I'm trying to run it under Kubuntu 16.04 PHP7 and MySQL5.7. Connection to database can not be established. There is no error message, the execution ends with the row for connection to base, and as a result report_before from the code is typed, but report_after is not.

<?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');
        }
    } 

}

推荐答案

问题在这里:

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

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

此扩展名自PHP 5.5.0起不推荐使用,并已从以下版本中删除. PHP 7.0.0.

This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0.

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

use mysqli, almost the same but you will have to upgrade all your code.

这篇关于PHP7无法连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆