Can't link DataTables to my SQL database.

Can't link DataTables to my SQL database.

kieranbarlowkieranbarlow Posts: 2Questions: 1Answers: 0

Hello, apologies in advance i'm a newbie when it comes to server side scripting, I'm currently trying to link up DataTables with my sql database which are both hosted on VPS.

I have the following script at the bottom of my .html page

$(document).ready(function() { $('#example').dataTable( { "processing": true, "serverSide": true, "ajax": "server_processing.php", "columns": [ { "data": "first_name" }, { "data": "last_name" }, { "data": "position" }, { "data": "office" }, { "data": "start_date" }, { "data": "salary" } ] } ); } );

And I have the following code in my server_processing.php file but for some reason I cannot link them up or show the information in my database - I get the internal server error 500 message.

<?php

// DB table to use
$table = 'test-table';

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

// Array of database columns
$columns = array(
array( 'db' => 'first_name', 'dt' => 0 ),
array( 'db' => 'last_name', 'dt' => 1 ),
array( 'db' => 'position', 'dt' => 2 ),
array( 'db' => 'office', 'dt' => 3 ),
array(
'db' => 'start_date',
'dt' => 4,
'formatter' => function( $d, $row ) {
return date( 'jS M y', strtotime($d));
}
),
array(
'db' => 'salary',
'dt' => 5,
'formatter' => function( $d, $row ) {
return '$'.number_format($d);
}
)
);

// SQL server connection information
$sql_details = array(
'user' => 'username-test',
'pass' => 'testing',
'db' => 'database-test',
'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 )
);

<?php > ?>

Again apologies.

Can somebody point me in the right direction?

Answers

This discussion has been closed.