Avatar of Overthere
Overthere
 asked on

Parsing error with JSON

I am using some coding from datatables - and yes a newbie,
I have problems with the data not being pulled and after some debugging, I have this error:

Parse error on line 1:
SSP: : simple($_GET,
^
Expecting '{', '['

I have attached the snippet of coding and have tried several syntax but can not seem to get it right. Long day.
I have also posted the coding from the entire page...
Could someone be as so kind as to help with it? Thank you...


);
echo json_encode(
	SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

Open in new window


<?php

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
 */

// DB table to use
$table = 'datatables_demo';
echo $table;

// Table's primary key
$primaryKey = 'id';
echo $primaryKey;

// Array of database columns which should be read and sent back to DataTables.
// The `db` parameter represents the column name in the database, while the `dt`
// parameter represents the DataTables column identifier. In this case object
// parameter names
$columns = array(
	array( 'db' => 'first_name', 'dt' => 'first_name' ),
	array( 'db' => 'last_name',  'dt' => 'last_name' ),
	array( 'db' => 'position',   'dt' => 'position' ),
	array( 'db' => 'office',     'dt' => 'office' ),
	array(
		'db'        => 'start_date',
		'dt'        => 'start_date',
		'formatter' => function( $d, $row ) {
			return date( 'jS M y', strtotime($d));
		}
	),
	array(
		'db'        => 'salary',
		'dt'        => 'salary',
		'formatter' => function( $d, $row ) {
			return '$'.number_format($d);
		}
	)
);

// SQL server connection information
$sql_details = array(
	'user' => 'root',
	'pass' => '1Lanceandme2',
	'db'   => 'testexample',
	'host' => 'localhost'
);


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP
 * server-side, there is no need to edit below this line.
 */

require( 'ssp.class.php' );

echo json_encode(
	SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

Open in new window

JSONAJAXjQueryPHP

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Ray Paseur

JSON_Encode() function expects a string, an array, or an object for input.  What is the value produced by this static method?

SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns );
Overthere

ASKER
That's a good question! I should have dump the vars. Here are the results of doing so: ( I starred out the pass -didn't want to post that!)

datatables_demo
id
Arrayarray(4) { ["user"]=> string(4) "root" ["pass"]=> string(12) "************" ["db"]=> string(11) "testexample" ["host"]=> string(9) "localhost" } array(0) { }
 {"error":"An error occurred while connecting to the database. The error reported by the server was: could not find driver"}

Open in new window


I have checked to ensure the drivers are installed by doing this: (and they did exist and I got my php info too.)
And I checked the php.ini too.  
I do not know what else to check - pathing problem ? but where?
Once again Ray, I am lost..sigh


<?PHP
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
    echo 'We don\'t have mysqli!!!';
} else {
    echo 'Phew we have it!';
}

?>

<?php
phpinfo(); 
?>

Open in new window

Overthere

ASKER
Added note. I am using Web Matrix 3. One site uses Php 5.3 and it reports that it has mysqli.
The site that I am having problems with is set to use PHP 5.4 and says it DOESN'T have mysqli!
Each site can be set to a different language etc.
So, how do I fix that site that can not find the mysqli?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Overthere

ASKER
Thank you Ray -
I am going to try your coding and the advice....
I really like PHP, and gaining more experience with it and with the sometimes problems.
But a lot to learn yet.
I have a lot of experience with other languages (some arcade now -  ha ha!) and with XML processing (bunches!)
Right now, I am trying to resolve the pathing issue to the new installed version of PHP - it keeps showing the old version - boo! I think once that is resolved, its going to be easier.
Like eating an elephant - one bite at a time....
Overthere

ASKER
as always good stuff from Ray!
Ray Paseur

Thanks for the points.  

This article may not be viewable yet, but you can bookmark it and come back in a day or two.  It's largely inspired by your question here, so it covers some of the ways of understanding XML and JSON - similarities and differences - with PHP and JavaScript code examples.
https://www.experts-exchange.com/articles/22519/Understanding-JSON-in-PHP-and-JavaScript-Applications.html
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.