index.php
<?php
include ('db.php'); // db connections
include ('functions.php'); // I need some functions
?>
The same php functions I need via jquery.ajax call.
$.post('functions.php', {vars}, function(data) {
console.log(data);
});
I'm getting error - $db is not defined because $db.php is not included in functions.php;
If I include db.php inside functions.php I'm getting error inside index.php - $db is already declared.
for now I repeat the same functions inside functions.php and an another file with db.php included, and I call it with ajax, but hope there is a more clever solution.
require_onceon both includes, so it will always load only once.functions.phpdirectly via ajax. Wouldn't that file only contain function definitions and not any directly-executed code?functions.phpgets some data from database, proccessed via js Is that odd?.dbinsidefunctionsandfunctionsinsideindexwithrequire_once?