[英]PHP script breaks at MySQL connect when called through Apache
I have a PHP script that will not run through Apache. 我有一个不会通过Apache运行的PHP脚本。 It is breaking at a mysql_connect
command - 它在mysql_connect
命令处中断-
$connection = mysql_connect('localhost','root','password');
I can view output before this command, but the script stops running at this line. 我可以在此命令之前查看输出,但是脚本在此行停止运行。 It would otherwise go on to produce a HTML table containing database table information. 否则它将继续产生包含数据库表信息的HTML表。
When running the script using php script.php
from the command line it executes correctly. 从命令行使用php script.php
运行脚本时,它将正确执行。 However when I run curl localhost/script.php
or just connect to it from a browser, it does not. 但是,当我运行curl localhost/script.php
或只是从浏览器连接到它时,它没有。 What is causing / How can I resolve this issue? 是什么原因/如何解决此问题?
Turning on logging revealed the error: 打开日志记录显示错误:
Fatal error: Call to undefined function mysql_connect() in /var/www/html/php/sqltable.php on line 11
line 11 being: 第11行是:
$connection = mysql_connect('localhost','root','password');
A ways to debug it. 一种调试它的方法。
First check if your php error reporting is turned on 首先检查您的php错误报告是否已打开
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
Then create a condition to check wether you can connect or not 然后创建一个条件来检查是否可以连接
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.