-1

I posted another question that is similar to this but I believe this to be a separate issue. Accessing MySql Database from PHP file on local host

While trying to execute the following line

$db = mysql_connect('ipaddress','username','password!!') or die("Connection error");

On my local raspberry pi lamp web server I get a internal 500 server error. It doesn't matter if I try and connect to an external Database or the local one that I want. I get the same internal 500 error response.

update:

After checking the error.log file it appears this is the reported error

"Call to undefined function mysql_connect() in [path]"

4

2 回答 2

2

你没有为php安装mysql,或者php找不到安装。创建一个 phpinfo() 站点并在那里查找 mysql。如果不存在,请尝试执行 apt-get install php5-mysql

于 2013-09-22T20:49:36.910 回答
0

mysql_connect 已弃用,很快就会从 PHP 主干中删除,如果这是一个非常新的 PHP 或 MySQL 安装,可能会出现问题,那么新的开发真的应该使用 MySQLi 或 PDO 库来完成

这就是你在 MySQLi 中的做法(面向对象)

$mysqli = new MySQLi($db_server, $db_username, $db_password, $db_database);

(程序)

$mysqli = mysqli_connect("example.com", "user", "password", "database");

还要确保 DB 用户有权访问相关数据库,如果您访问远程数据库,您还必须将源添加到 mySQL 服务器(域或 IP 地址)的批准列表中。

500 错误很难诊断,500 仅仅意味着服务器不理解,或者无法处理请求(它是当其他错误不适用时发生的错误)好消息是服务器实际上正在接收请求。

于 2013-09-22T20:54:07.497 回答