PHP - Call to undefined function requiring a file from a different folder and using namespace -


edit: removed namespaces , still doesn't work. if move file in same folder blog.php, works. moment, i'm connecting database again in admin file, supose that's not solution.

this first question posted. i've started learn php , i'm stuck problem. i've searched answers couldn't find related.

so here's problem.

i'm trying build simple blog , want create admin section. created new folder 'admin' , file 'index.php' inside it. when require 'blog.php' file connects database, error:

'fatal error: call undefined function blog\db\connect() in c:\xampp\htdocs\blog\blog.php on line 5' .

in file db.php contains database related functions use namespace blog\db. what dont't if move admin 'index.php' file in same folder blog.php works.

here code both files.

blog.php :

 <?php      require 'functions.php';     require 'db.php';     //connect db     $conn = blog\db\connect($config);     if (!$conn) die('problem connecting db!');     ?> 

admin/index.php

<?php  require '../blog.php'; ?> 

db.php uses:

namespace blog\db; 

thank you!

try changing

$conn = blog\db\connect($config); 

to

$conn = \blog\db\connect($config); 

even though not sure if should work don't think it's namespacing problem.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -