Use $db in external page
Use $db in external page
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I am trying to create the first pages with datables.
Like any site, I need a login, and would like to create a page for importing data from an external JSON.
Since database access has already been defined in my datatables, and includes a class that handles different types of databases.... I would like to use this class for my login and import function (Database.php).
Functions as:
"$mysqli->prepare("SELECT id, username, password, salt FROM members WHERE email = ? LIMIT 1")) "
How do I use this datatables package class for external applications from datatables (login and import)?
Could you, kindly, give me a small example?
Answers
Sure! The reference documentation for the class is here.
You’d include the
Datatables.php
file like normal, which will get you that magic$db
variable automatically, then you can do:With a limit you need to build the query more expilicity:
Allan
My script is now:
but return this error:
I've been testing, I'm going crazy because I don't understand why:
If I write like this IT WORKS:
But if I write like this it does NOT work:
Why?!?!!?!
If you don't pass the db handler into your function it can't be there ... The db handler is a global variable.
A final option is:
You have to remember that PHP doesn't scope its variables like Javascript does. In PHP they are locally scoped by default.
Allan