以下代码适用于 PHP5 和 MySQL5.6。在 Kubuntu 和 Windows 下。在这种特殊情况下,我尝试在 Kubuntu 16.04 PHP7 和 MySQL5.7 下运行它。无法建立与数据库的连接。没有错误消息,执行以连接到基础的行结束,因此代码中的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');
}
}
}
最佳答案
问题出在这里:
$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.
使用mysqli,几乎相同,但你必须升级所有代码。
关于mysql - PHP7无法连接MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42051795/