PHP7 can't connect to MySQL

点点圈 提交于 2019-12-24 10:59:26

问题


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

}


回答1:


Problem is here :

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

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

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

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



来源:https://stackoverflow.com/questions/42051795/php7-cant-connect-to-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!