Srs, bom dia!
Eu criei uma classe para controle das constantes. É impresso um erro nesta classe eu sei exatamente onde está o ponto do erro, mas não sei o porque e como resolve-lo. Se alguém conseguir ajudar eu agradeço.
class Constants
{
const DEBUG = false;
public function __construct()
{
define('DRIVE', 'mysql');
define('HOST', 'localhost');
define('DB_NAME', 'voxus' );
define('USER', 'root');
define('PASSWORD', 'xura123@');
define('DEBUG', false);
}
public function getDrive()
{
return DRIVE;
}
public function getHost()
{
return HOST;
}
public function getDBName()
{
return DB_NAME;
}
public function getUser()
{
return USER;
}
public function getPassword()
{
return PASSWORD;
}
public static function getDebug()
{
return self::DEBUG;
}
}
<?php
require_once("Constants.php");
class Connection
{
public static function connect()
{
$constant = new Constants();
$connection = new PDO($constant->getDrive().
':host='.$constant->getHost().
';dbname='.$constant->getDBName(),
$constant->getUser(),
$constant->getPassword());
return $connection;
}
}
?php
require_once('../../classes/importClasses.php');
require_once('../../model/task/database.php');
try{
$factory = new TaskFactory();
$task = $factory->create($_POST);
if($_FILES['file']['tmp_name']):
$extent = strtolower(substr($_FILES['file']['name'], -4));
$file_name = md5(time()).$extent;
$directory = "c:/xampp/htdocs/voxus/views/files/";
move_uploaded_file($_FILES['file']['tmp_name'], $directory.$file_name);
$task->setFile($directory.$file_name);
endif;
$task->setCode(createCode());
insert($task); //<-*****************************
header('Location:../../views/tasks.php');
die();
}catch(Exception $e){
Insure::takeCare($e);
}
function connection()
{
$connection = Connection::connect();
return $connection;
}
function insert(Task $task)
{
Insure::checkData($task->getName());
Insure::checkData($task->getDescription());
$query = "INSERT INTO tasks(code, name, description, file)
VALUES(:code, :name, :description, :file)";
$stmt = connection()->prepare($query); <- ERRO ACONTECE NESTE TRECHO
$stmt->bindValue(':code', $task->getCode());
$stmt->bindValue(':name', $task->getName());
$stmt->bindValue(':description', $task->getDescription());
$stmt->bindValue(':file', $task->getFile());
$stmt->execute();
}