简体   繁体   English

通过Apache调用MySQL时,PHP脚本在MySQL连接处中断

[英]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.

相关问题 在PHP脚本中调用时,无法通过Perl建立MySQL连接 - Unable to make a MySQL connection through Perl when called in a PHP script 使用mysqli或PDO时无法通过PHP脚本连接到MySQL,但是mysql可以正常工作 - Unable to connect to MySQL through PHP script when using mysqli or PDO BUT mysql works 如何使用 php 通过 apache 服务器调用 selenium 执行 python 脚本? - How to execute a python script with selenium called by php through apache server? Windows Mysql 5.5和php5.2:mysql_connect()中断脚本,无输出 - Windows Mysql 5.5 and php5.2: mysql_connect() breaks the script, no output 通过Apache调用脚本时,带有PHP 5.4的XHP不影响解析器 - XHP with PHP 5.4 not affecting the parser when script is called via Apache 通过exec()调用时,长时间运行的PHP脚本会停止,但在通过CLI调用时会结束 - Long running PHP script stops when called through exec(), but finishes when called through the CLI 从exec()调用PHP脚本时,MySQL函数不起作用 - MySQL functions not working when PHP script is called from exec() 通过PDO通过PHP连接到MySQL - connect to mysql through php with pdo 无法通过PHP连接到MySQL - Cannot connect to MySQL through PHP mysql + apache + php安装脚本 - script for mysql + apache + php installation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM