获取提取路径时出错

时间:2017-11-16 00:56:15

标签: php

我实际上是在连接文件测试器中检查我的连接以检查它是否连接到数据库但问题是我收到此错误

Warning: include(obj\database_connection\SqlHandler.php): failed to open stream: No such file or directory in /home/devhostt/public_html/bcc/gradingsystemmodule/root/root.php on line 16

Warning: include(): Failed opening 'obj\database_connection\SqlHandler.php' for inclusion (include_path='/home/devhostt/public_html/bcc/gradingsystemmodule:.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php') in /home/devhostt/public_html/bcc/gradingsystemmodule/root/root.php on line 16

Fatal error: Class 'obj\database_connection\SqlHandler' not found in /home/devhostt/public_html/bcc/gradingsystemmodule/function/checkconnection.php on line 8

这是我的代码设置&得到路径(root.php)

<?php
error_reporting( E_ALL );

define("setRealpath", realpath("../"));

const ERROR_EXCEPTION_MESSAGE = "SOMETHING WENT WRONG HERE: ";

try
{
$getPath = array(setRealpath, get_include_path());

if(!set_include_path(implode($getPath, PATH_SEPARATOR)))
{
define("setRealpath", realpath("./"));
$getPath = array(setRealpath, get_include_path());
set_include_path(implode($getPath, PATH_SEPARATOR));
}

function GetClassFile($class)
{
$file = str_replace('/', '\\', $class).".php";
include $file;
}

spl_autoload_register('GetClassFile');

}
catch(Exception $x)
{
die(ERROR_EXCEPTION_MESSAGE.$x->getMessage());
}

?>

这是我的连接文件(SqlHandler.php)。

<?php
namespace obj\connection_database;
use \PDO;
class SqlHandler extends Connection
{
const ERROR_EXCEPTION_MESSAGE = "SOMETHING WENT WRONG HERE:";

protected $db = null;

public function __construct()
{
$this->db = $this->getConnection();
}

public function checkConnection()
{
if($this->db)
{
return "CONNECTED";
}
return "NO CONNECTION";
}
}
?>

最后在这个文件中,我试图检查连接(checkconnection.php)

<?php
error_reporting(E_ALL);

include "./root/root.php";

use \obj\database_connection\SqlHandler;

$checkConnection = new SqlHandler;

echo $checkConnection->checkConnection();
?>

1 个答案:

答案 0 :(得分:0)

现在我发现了我的错误,唯一的错误就是我使用的是旧版本的php,而不是使用php 7.1版本,我使用的是PHP 5.所以我改变它并且它有效。