1
defines.php
$HOST = "localhost";
$USER = "root";
$PASS = "";
$DB = "banco";
config.php
function conexao(){
try{
include_once("defines.php");
$conn = new PDO("mysql:host=".$HOST.";dbname=".$DB."",$USER,$PASS);
}catch(PDOException $e){
$e->getMessage();
}
return $conn;
}
func.php
I’m trying to include this connection in this role
include "pdo/config.php";
$conn = conexao ();
function noticias($conn){
// Faz algo
}
But it’s making a lot of mistakes
Notice: Undefined variable: HOST in /home/vol8_6/epizy.com/epiz_23239906/htdocs/Pdo/config.php on line 5
Notice: Undefined variable: DB in /home/vol8_6/epizy.com/epiz_23239906/htdocs/Pdo/config.php on line 5
Notice: Undefined variable: USER in /home/vol8_6/epizy.com/epiz_23239906/htdocs/Pdo/config.php on line 5
Notice: Undefined variable: PASS in /home/vol8_6/epizy.com/epiz_23239906/htdocs/Pdo/config.php on line 5
Notice: Undefined variable: Conn /home/vol8_6/epizy.com/epiz_23239906/htdocs/Pdo/config.php on line 9
Warning: Missing argument 1 for noticias(), called in /home/vol8_6/epizy.com/epiz_23239906/htdocs/aqv/lancamentos.php on line 11 and defined in /home/vol8_6/epizy.com/epiz_23239906/htdocs/func/var.php on line 4
Not loading the file
defines.php
. Exchange theinclude
/include_once
forrequire_once
. This way it generates an error and for the execution of the script if it cannot include the file. By the way, pq vc made a file only with the data of the connection and another with the connection? Being that the file of the connection was namedconfig.php
... Let’s face it: user, password, and other database information are also settings. They should be in the fileconfig.php
, nay?!– LipESprY
In your php files you have the tag "<? php ?>" ?
– Wanderson Rodrigo
@Wandersonrodrigo We must assume so. Otherwise the PHP interpreter would not generate the errors... Right?!
– LipESprY
has yes Wanxerson, did not work Lip, same errors, about the defines file was to make the code get cleaner
– goio
I’ll formulate an answer and you give a Ctrl+C > Ctrl+V. I can change the structure of your project a little?!
– LipESprY
@Lipespry if it works yes, because I will call this function on more than one page
– goio