Fatal error: Call to a member function transaction() on a non-object
Fatal error: Call to a member function transaction() on a non-object
I have followed the Getting Started page on how to configure this Editor as I think this product is great, but would love to see it integrated into my site. Having a difficult time configuring this and I keep getting this error. I have tried to follow what this person did, but to no success. (https://datatables.net/forums/discussion/22363/fatal-error-call-to-a-member-function-val-on-a-non-object-on-line-1018).
Php Version of my server: 5.4
Can someone help me fix this error? Fatal error: Call to a member function transaction() on a non-object in /html/.../DataTables-Editor/Editor/Editor.php on line 547
The error in question is this line of code
$this->_db->transaction();
Here is my configuration php
require(dirname(DIR) . '/DataTables-Editor/DataTables.php');
use DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Join,
DataTables\Editor\Upload,
DataTables\Editor\Validate;
function init_datatable_editor(){
$db="";
$editor = Editor::inst( $db, 'tblNameGoesHere' );
$editor->fields(
Field::inst( 'My Field 1' ),
Field::inst( 'My Field 2' ),
Field::inst( 'My Field 3' ),
Field::inst( 'My Field 4' ),
Field::inst( 'My Field 5' ),
Field::inst( 'My Field 6' ),
Field::inst( 'My Field 7' ),
Field::inst( 'My Field 8' ),
Field::inst( 'My Field 9' ),
Field::inst( 'My Field 10' ),
Field::inst( 'My Field 11' ),
Field::inst( 'My Field 12' ),
Field::inst( 'My Field 13' ),
Field::inst( 'My Field 14' )
)
->process( $_POST )
->json();
}
Can someone tell me why I am receiving this error? Is it my configuration? I followed pretty closely to the "Getting Started" tutorial.
Thank you.
This question has an accepted answers - jump to answer
Answers
It seems to be that within the troubled function
public function process ( $data )
{
$this->_processData = $data;
$this->_formData = isset($data['data']) ? $data['data'] : null;
I have added the if(count(... Looking at the array $data it seems to be coming up with 0. This seems that maybe it's not properly connecting to the database? Would be nice if there was an error message stating that connection failed. Could it be my port number? I have triple checked my values in the database configuration and it looks fine. The only value I do doubt is the "type" variable shown below...
$sql_details = array(
"type" => "", // Database type: "Mysql", "Postgres", "Sqlite" or "Sqlserver"
"user" => "", // User name
"pass" => "", // Password
"host" => "", // Database server
"port" => "", // Database port (can be left empty for default)
"db" => "", // Database name
"dsn" => "" // PHP DSN extra information. Set as
charset=utf8
if you are using MySQL);
If I want to choose Mysql is that all I type in? If so, that's what I have done. Not sure what else to check here to see if this is properly connecting.
To make certain that I am able to connect I just did this small experiment. This was able to connect to my database and report back data from my database correctly.
So i am just a lost as to what am I missing. This product is very promising and I don't want to dismiss it, but I am having such a hard time getting this to work. Any help would be greatly appreciated.
Thanks!
That would do it. You are passing in an empty string as the database connection!
Try using:
instead.
Why: The DataTables.php file will create a global
$db
variable which is the connection to the database. You need to be able to access that in your function, and due to PHP's wacky way of handling globals, the line of code I suggested above will make it accessible.A much better solution would be to pass in the
$db
variable into your function.Allan
This is what I have tried so far and thanks Allan for the advice. I have a feeling we are getting close to solving this.
Removed the $db="" from my main php script which initializes everything.
In my main php script I added the global $db; at the top of my script per your request, but I keep receiving an undefined variable $db.
What I did next was remove that global and put it inside the DataTables.php, but received the same results.
Then I put it into the Bootstrap.php file and received the same results.
What I did next was this. Inside my Boostrap.php I added this function at the bottom.
//
// Database connection
// Database connection is globally available
//
$db = new Database( $sql_details );
function getDB(){
return $db = new Database( $sql_details );;
}
Inside my main script I put this in my function.
function init_datatable_editor(){
$editor = Editor::inst( DataTables\getDB(), 'HairStyles' );
}
Now this is the error that I am receiving...
Notice: Undefined variable: sql_details in /home/.../wp-content/DataTables-Editor/Bootstrap.php on line 62
Fatal error: Uncaught exception 'Exception' with message 'Unknown database driver type. Must be one of Mysql, Oracle, Postgres, Sqlite, Sqlserver' in /home/.../wp-content/DataTables-Editor/Database/Database.php:56 Stack trace: #0 /home/.../wp-content/DataTables-Editor/Bootstrap.php(62): DataTables\Database->__construct(NULL) #1 /home/content/24/9309924/html/wp-content/mu-plugins/functions.php(499): DataTables\getDB() #2 /home/.../wp-content/plugins/insert-php/insert_php.php(48) : eval()'d code(1): init_datatable_editor() #3 /home/.../wp-content/plugins/insert-php/insert_php.php(48): eval() #4 [internal function]: will_bontrager_insert_php('<script type="t...') #5 /home/.../wp-includes/plugin.php(235): call_user_func_array('will_bontrager_...', Array) #6 /home/.../wp-includes/post-template.php(240): apply_filters('the_content', '<script type="t...') #7 /home/.../html/wp-content/themes/custo in /home/.../html/wp-content/DataTables-Editor/Database/Database.php on line 56
Any other suggestions on how to configure this? Or am I getting close to configuring this?
I found a Stack Overflow post that states that you are allowed to declare a global within a function (didn't know that). Once I did that it no longer complained about the undefined variable.
Now I get this error. Again, no clue what this means, but at least it's progress.
{“error”:”SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘1 as ‘Address 1’, Address 2 as ‘Address 2’,
City
as ‘City’,Zip
as ‘Zip’, `L’ at line 1″,”data”:[]}Do you have any idea what this means? Going to start searching, but I thought I would ask.
Thanks for the help so far!
Fixed my issue. It was the fields were not named correctly in my script. They did not match what was in my database. Once I corrected that I see now JSON values that are inside my database.
Now, I need to look for a tutorial on how to put then inside the table.
Thanks for the help!
Good to hear you've been able to make process with it - thanks for posting back!
Allan