1

I have a PHP script that will not run through Apache. It is breaking at a mysql_connect command -

$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.

When running the script using php script.php from the command line it executes correctly. However when I run curl localhost/script.php or just connect to it from a browser, it does not. 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:

$connection = mysql_connect('localhost','root','password');
unclemeat
  • 4,831
  • 5
  • 24
  • 49

1 Answers1

2

A ways to debug it.

First check if your php error reporting is turned on

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);
?>
Jhonathan H.
  • 2,702
  • 1
  • 17
  • 26
  • Thanks, this made realize that I had not restarted my apache service since installing the MySQL PHP modules, and therefore the functions were not recognized. – unclemeat Feb 25 '14 at 03:21
  • @unclemeat yes regarding the error http://stackoverflow.com/questions/13825108/undefined-function-mysql-connect heres a link similar to that. – Jhonathan H. Feb 25 '14 at 03:23
  • Yes, I didn't realize that I had to restart the Apache service for newly installed PHP functions to be recognized. – unclemeat Feb 25 '14 at 03:24