I think you should be able to do a
$db = database();
then use
$db->connection();
:-* not work
Notice: Undefined variable: db in C:\xampp\htdocs\elk104\Ajac\lib\class\CustomAJAXChat.php on line 19
Fatal error: Call to a member function database() on null in C:\xampp\htdocs\elk104\Ajac\lib\class\CustomAJAXChat.php on line 19
class CustomAJAXChat extends AJAXChat {
// Initialize custom configuration settings
function initCustomConfig() {
global $db_name,$db_connection;
$db->database();
// Use the existing ElkArte database connection:
$this->setConfig('dbConnection', 'link', $db_connection);
}
// Override the database connection method to make sure the ElkArte database is selected:
function initDataBaseConnection() {
global $db_name;
// Call the parent method to initialize the database connection:
parent::initDataBaseConnection();
// Select the ElkArte database:
$this->db->select($db_name);
if($this->db->error()) {
echo $this->db->getError();
die();
}
}
CustomAJAXChat.php (https://github.com/Frug/AJAX-Chat/blob/smf/chat/lib/class/CustomAJAXChat.php#L13)
class CustomAJAXChat extends AJAXChat {
// Initialize custom configuration settings
function initCustomConfig() {
global $db_name,$db_connection;
// Use the existing ElkArte database connection:
$this->setConfig('dbConnection', 'link', $db_connection);
}
// Override the database connection method to make sure the ElkArte database is selected:
function initDataBaseConnection() {
global $db_name;
// Call the parent method to initialize the database connection:
parent::initDataBaseConnection();
// Select the SMF database:
$this->db->select($db_name);
if($this->db->error()) {
echo $this->db->getError();
die();
}
}
Make sure you have it as
db = database();
not
db->database();
Its a static db object, not a method, so you have to assign it via = to some variable (here we use $db) before you try to use its methods via $db->blabla
Thanks
@Spuds, This exceeds my knowledge.
It's not really that much different:
// Initialize custom configuration settings
function initCustomConfig() {
$db = database();
$db->database();
Not work :-[
I think with removing " $db_connection" will bridge systems difficult to connect to the database. Why it was removed?
I'm not sure why you want to use the connection directly...
I'll have a look at the code this evening, and if you can point me to the file that uses $db_connection in your code, that would speed up the answer. ;)
What I was trying to say is I think you have a typo and used $db->database() and it should be $db=database() At least I think. Probably best to let emanuele take a look !
class CustomAJAXChat extends AJAXChat {
// Initialize custom configuration settings
function initCustomConfig() {
global $db_name,$db_connection;
$db = database();
$db_connection = $db->connection();
// Use the existing ElkArte database connection:
$this->setConfig('dbConnection', 'link', $db_connection);
}
:) :) :) :) :)
That was @Spuds. I'm so happy. Now I can solve the other problems. db_prefix and so..
Many Thanks you both. But I think it will not be my last question :-[ .
Database connection works. Boards as channels are read. Only the user will not be displayed. For Today's first final, it goes on tomorrow.
Edit. Database connection to the tables from Ajax Chat is not working :-[
I dont get any further :'(
I have worked my way through and between SMF and ElkArte found no differences between the user and the login. Maybe someone has the time and could watch it times. Responsible for logging and the user are the following files:
- ajac\lib\custom.php
- ajac\lib\class\CustomAJAXChat.php
The install.php is not finished yet. This includes only the installation, not the uninstall. Because beta status is the button for the chat, only available for the Admin.
Already in advance, thank you very much :)
Do not use in a liveaboard!
I believe I have found the error. Homemade, probably. It is up to my own Addon "Start Page". Only where the fault lies, I do not know. Will report as soon as I've found the cause.
It is the .htaccess
DirectoryIndex index.php?action=startpage index.php index.html index.htm
So I wanted to set the home page for my website.