/    Sign up×
Community /Pin to ProfileBookmark

Call to undefined function BlogDBconnect?

Hi,

This is driving me crazy! Here is my code:

[code=php]<?php

require ‘../blog.php’;

view(‘admin/create’);[/code]

This file is called index.php which is in a directory called admin.

Here is the code for another file called blog.php which is the same directory as admin.

[code=php]<?php

require ‘functions.php’;
require ‘db.php’;

$conn = BlogDBconnect($config);

if (!$conn) die(‘Could not connect’);[/code]

Now, when I navigate to admin/index.php I get an error:

Fatal error: Call to undefined function BlogDBconnect() in C:xampphtdocssandboxblogblog.php on line 6.

I tried putting namespace BlogDB and deleting Blog from the blog.php file but I keep getting that error.

I don’t know what the problem is, other pages that use blog.php are working fine.

Thanks

to post a comment
PHP

19 Comments(s)

Copy linkTweet thisAlerts:
@TW79Apr 25.2014 — Try changing "require" to "include"
Copy linkTweet thisAlerts:
@NogDogApr 25.2014 — What version of PHP are you running this under? (Anything earlier than 5.3.0, and PHP won't understand the namespace notation [or concept] being used in your code.)
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 25.2014 — nah now even the other pages are not working
Copy linkTweet thisAlerts:
@NogDogApr 25.2014 — Yeah, I'd leave those require()'s as they are: you want an error if it can't find an include file. ?

Should there be a leading "":
[code=php]
$conn = BlogDBconnect($config);
[/code]

?

I've not really used namespaces yet in PHP, so may not be a whole lot of help. ? Do any of the files in question actually have a "namespace" declaration anywhere (normally before any other PHP code)?
Copy linkTweet thisAlerts:
@ShrineDesignsApr 25.2014 — The problem is the various depths of directories and PHP's internal directory pointer.

When opening [i]blog/admin/[/i] all relative URIs (i.e. links) point to that directory.

You can prevent this by using absolute URIs (e.g. [i][b]/[/b]xampp/htdocs/sandbox/blog/[/i]).

In situations where you cannot use absolute URIs (i.e. production application). You can do something along these lines:

Place this at the top of each page (do not add to files that are included) change the value of $root to resolve to the root directory of the script.[code=php]// path resolution
$root = './';[/code]
for pages in blog/<dir>.[code=php]// path resolution
$root = '../';[/code]

Then alter all the include() and require() calls to use this variable.[code=php]include $root . 'inc/functions.php';[/code]Hope this helps. Sorry for lack of explanation of POSIX directory pointers.
Copy linkTweet thisAlerts:
@NogDogApr 25.2014 — I suspect it's not an include problem, as require() will throw a fatal error that's pretty obvious if it can't find the specified file. I'm more inclined to think it's a namespace issue.
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 25.2014 —  Do any of the files in question actually have a "namespace" declaration anywhere (normally before any other PHP code)?[/QUOTE]

yh, the db.php file has namespace BlogDB on the top line before any code.
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 25.2014 — this is driving me nuts, I looked at the source code of the tutorial I'm following, and I have the exact same code!
Copy linkTweet thisAlerts:
@NogDogApr 26.2014 — Is there a link to the tutorial you could give us?
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 26.2014 — Is there a link to the tutorial you could give us?[/QUOTE]

It's a premium tutorial, but I downloaded the source code, sou you can check it.

https://onedrive.live.com/?gologin=1&mkt=en-GB#cid=464AE6D344C62132&id=464AE6D344C62132%21130

blog 1 folder is the tutorials source code, blog is mine
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 26.2014 — Interesting..

Even when I remove the namespace declaration and notations, the other pages continue to work fine except admin/index.php, except this time the fatal error says undefined function connect() and not Blog/DB/connect().

So the problem seems to be around admin/index.php not recognizing the statement: require '../blog.php'.
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 26.2014 — Aha, I have moved the index.php file, that is in the admin folder, one directory up, so that now it is in the same directory as blog.php (and renamed it index2.php because there is already an index.php file), and changed the require '../blog.php' statement to require 'blog.php' and it works!

So the problem is definately something to go with the statement require '../blog.php' because when the file is in its own directory it does not work but when it is in the same directory as blog.php it works!:S
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 26.2014 — Yeah, I'd leave those require()'s as they are: you want an error if it can't find an include file. ?

Should there be a leading "":
[/QUOTE]


That was just a typo I made, its not on the file. Like I said before, all the other pages indeed working and they require blog.php so the rpoblem is definately not the blog.php file but the index.php that is in the admin folder.
Copy linkTweet thisAlerts:
@NogDogApr 27.2014 — I'm probably missing something obvious here, but if your require() failed to load the file, you should have gotten a fatal error and never made it to the point where you got the undefined function error. ?
Copy linkTweet thisAlerts:
@Imam_GainsauthorApr 30.2014 — I'm probably missing something obvious here, but if your require() failed to load the file, you should have gotten a fatal error and never made it to the point where you got the undefined function error. ?[/QUOTE]

I know, exactly!
Copy linkTweet thisAlerts:
@mamyhJul 19.2016 — i got the same problem . how can i get rid of it????
Copy linkTweet thisAlerts:
@mamyhJul 19.2016 — nah now even the other pages are not working[/QUOTE]

i got the same problems. Can you please help me
Copy linkTweet thisAlerts:
@davidstephanJul 19.2016 — Have you added this dbconnect funtion code with your program

function dbConnect($db="") {

global $dbhost, $dbuser, $dbpass;

$dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass)
or die("The site database appears to be down.");

if ($db!="" and !@mysql_select_db($db))
die("The site database is unavailable.");

return $dbcnx;

}
×

Success!

Help @Imam_Gains spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...