Link to home
Start Free TrialLog in
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

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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 );
Avatar of Overthere
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

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?
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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....
as always good stuff from Ray!
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