0

i have a php script does some computations then connects to a mysql database to write some data. when i run the script from a terminal, the script runs fine. when i run the script from a webpage (starts when i click a button in the page), the script dies once it hits the mysql_connect statement in the php code.

not sure what code or data to provide you folks to help with the debug...just dies with no error message. if anyone has suggestions on what additional data to post, please let me know.

could it be some kind of permissions issue? for some reason at the terminal my account can access the mysqli libs containing the mysqli_connect functon, but the apache web user doesn't have those permissions? i'm stuck...have never seen this before.

test.php:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
connectToDB();
print "hi manny";

function connectToDB() {
$hostname = "XXXXX";
$port = "XXX";
$schema = "XXXX";
$username = "XXXXX";
$password = "XXXXX";

print "got inside\n";
$dbh = mysqli_connect($hostname, $username, $password, $schema, $port);
print "got connect\n";
// Check connection
if (!$dbh) {
    echo "connection failed\n";
    die("Connection failed: " . mysqli_connect_error());
 }
 echo "Connected successfully\n";
 return $dbh;
}
?>

when run from command line:

[manoli@app01 site1]$ php -f test.php
got inside
got connect
Connected successfully
hi manny

when run from webpage via ajax:
got inside


Fatal error: Call to undefined function mysqli_connect() in >/var/www/apps/site1/test.php on line 16

14
  • 2
    My guess would be you have PHP error reporting off and that's why there's no error message. Commented Nov 17, 2014 at 3:14
  • On what @Nordenheim said, turn error reporting on with ini_set('display_errors', 1); error_reporting(E_ALL); and show us what pops up. Commented Nov 17, 2014 at 3:18
  • If there's no error, how do you know mysql_connect is the issue? Commented Nov 17, 2014 at 3:18
  • i had error_reporting on. i added ini_set and now i see the following: <b>Fatal error</b>: Call to undefined function mysqli_connect() in <b>/var/www/apps/site1/handleRegistration.php</b> on line <b>80</b><br> <br> why would it not be able to find the mysqli_connect function when run from webpage, but it can from the command line? @darren Commented Nov 17, 2014 at 3:31
  • 2
    @user3255120 There's a very high chance your PHP is compiled without MySQLi support. Try running phpinfo(); and see if mysqli is there. Commented Nov 17, 2014 at 3:56

1 Answer 1

0

Looks like you don't have MySQLi enabled. You should check your phpinfo() for MySQLi support.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.