简体   繁体   中英

PHP file can't access MySQL database after changing server

So I have a PHP application running well on my local server, powered by Zend Server. After I uploaded it to the ubuntu server, it stops working, except for two php file, the index.php and register.php, which handles the user registration part. When I say working, it means I can view the page as in my local server but the internal process is not functioning. For example, when I try to register a user, it should tell me whether it is successful or not. Instead, it is a just a blank page.

I rule out the directory problem. All the path are relative and they are working fine. I also rule out the MySQL database problem as I can access the database and do everything with it. So I wrote the following script to test where php can access mySQL (the MySQL database is set up in the same host). So I wrote the following script:

<?php
ini_set("display_errors", 1);
error_reporting(E_ALL); 

require_once("config/connect_database_viewer.php");
echo $db_hostname;
echo "<br>";
echo "1";
echo $db_username;

$sql = "CREATE TABLE writer (UPC VARCHAR(15)) ENGINE MyISAM";
if ($db_server->query($sql)) {
        echo "the database works";
} else {
        echo "so it didn't even reach the server";
}

Fatal error: Fatal error: Class 'mysqli' not found in /var/www/viewer/angelo/config/connect_database_viewer.php on line 3.

But it doesn't make sense to me as I tried to install php5-mysql by this command: sudo apt-get install php5-mysql it comes back to me saying php5-mysql is already the newest version. And I checked the ubuntu page for the version, the php5-mysql module should include a mysqli extension. The php module is enabled too! Here is my connect_database_viewer.php file:

<?php
    $db_hostname = '127.0.0.1';
    $db_database = 'viewer';
    $db_username = 'juvo1';
    $db_password = 'juvo1';
    $db_server = new mysqli($db_hostname, $db_username, $db_password, $db_database);

    if ($db_server->connect_error) die($db_server->connect_error)

?>

You need to check the error log. It'll tell you where the error happened in your PHP script. Try looking in

/var/log/httpd/error.log

and see what it says.

If only the first line of your test script is printed, your include script creates an error. The reason can be that your include fails (maybe due to rights problem) or something inside the script. I would include the

ini_set("display_errors", 1);
error_reporting(E_ALL); 

to get the errors in the browser if your console (= error log?) does not mention anything else.

It appears that there are two problem in the process. The first one is that there are no mysqli module built-in for my version of php. People can install the php mysqli module with this command:

sudo apt-get install php5-mysqlnd

This stops the white page from showing up. But there is still warning about trying to connect via tcp. So I change the database conf php file from 127.0.0.1 to localhost. For more information, please refer to this link: mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket 'MySQL' (2) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM