为什么这个mysql_函数在PHP中未定义?

问题描述 投票:-3回答:2

这是我的数据库图像:

enter image description here

这行错误:

$con = mysql_connect("localhost","root","");

错误:

致命错误:未捕获错误:在C:\ xampp \ htdocs \ Trial \ insert.php中调用未定义函数mysql_connect():6堆栈跟踪:#0 {main}抛出C:\ xampp \ htdocs \ Trial \ insert.php在第6行

php insert
2个回答
0
投票

检查你的php版本我的调用echo phpinfo();,我猜它的版本问题,php 7不支持mysql功能,改用mysqli,它会为你工作


0
投票

除非您使用的是PHP 5.6或更低版本,否则mysql函数将无效。该功能在PHP 7.0+中删除。你应该使用mysqli(见下文)或PDO

// If your local DB connection is default
$host = 'localhost';
$username = 'root';
$password = '';
$database = 'YOUR_DB_NAME';

$con = mysqli_connect('$host',$username',$password,$database);
© www.soinside.com 2019 - 2024. All rights reserved.