问题描述:

I have a base.php file that do config database

define("HOST", "localhost"); // The host you want to connect to.

define("USER", "user"); // The database username.

define("PASSWORD", "pass"); // The database password.

define("DATABASE", "base");

$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);

$mysqli->set_charset("utf8");

if ($mysqli->connect_error) {

echo('error do not connected to database');

}

and any other page that will connect to base.php for use database like this:

<?php

include '../../Connections/base.php';

$query = "SELECT * FROM table";

// echo $query;

if ($result = $mysqli->query($query)) {

while ($row = $result->fetch_assoc()) {

echo $row['contain'];

}

}

else

{

echo $mysqli->error;

}

?>

It doing work in localhost with XAMMP software and can find Base.php path and receive data from database but when i upload it in my website it get me

Fatal error: Call to a member function query() error

I copy Base.php codes instead of ((include '../../Connections/base.php';)) code . it do work in website but it's not safe and of course i have a lot of file that i should copy Base.php codes on there

how can fix that? Thank you

网友答案:

Note that the relative path used in xampp is not the same as the relative path on an Internet web server.

In xampp the root directory is htdocs. In contrast an Internet server's root directory is the directory of your website.

Try removing one set of ../ from your include ../../Connections/base.php.

相关阅读:
Top