PHP - Using a function outside the file it has been created in

ahmed saleh

New Member
I have 3 php files. The first (connexion.php) one contains a function I use to create a new PDO connexion:\[code\]<?phpheader('Content-Type: text/html; charset=utf-8');date_default_timezone_set('Europe/Paris');function connexion($host, $user, $pass, $db){ $db_host = $host; $db_user = $user; $db_password = $pass; $db_database = $db; return $connexion = new PDO("mysql:host=$db_host;dbname=$db_database;charset=utf8", $db_user, $db_password);}?>\[/code\]The second file (my_function.php) contains a function that contains only one function that connects to a db and then is echoing some information. \[code\] <?php include(connexion.php); function my_first_function(){ try{ $connexion = connexion('localhost', 'user', 'user', 'mydb'); $connexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //some code that echoes information } catch(...){...} } ?>\[/code\]My problem is when I try to include that last file into my third php script in order to be abble to use the function. The script is not even launching. I just have 'internal error'. If I remove the include(my_function.php) my file is loaded properly. I don't get it. Hope someone can help me understand. Thanks in advance. Cheers. Marc. Here below the third file:\[code\]<?phpinclude('connexion.php');include('my_function.php');//some codemy_first_function();?>\[/code\]
 
Back
Top