DataTables warning: table id=example - An error occurred while connecting to the database. The error

DataTables warning: table id=example - An error occurred while connecting to the database. The error

pjustindaryllpjustindaryll Posts: 13Questions: 4Answers: 0
edited August 2019 in Free community support

May I ask for assistance regarding this guys? I manage to enable this guide https://editor.datatables.net/examples/simple/join.html. Now, I'm trying to use it on this guide. https://datatables.net/examples/data_sources/server_side.html

So what I did is I only populated this line

$sql_details = array(
'user' => '',
'pass' => '',
'db' => '',
'host' => ''

But it's saying this error.

DataTables warning: table id=example - An error occurred while connecting to the database. The error reported by the server was: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

I downloaded the whole dataTable example and just populate the $sql_details above. I'm using SQL SERVER 2012 via SQLSRV.

This is the whole server-side code.

<?php

/*
* DataTables example server-side processing script.
*
* Please note that this script is intentionally extremely simply to show how
* server-side processing can be implemented, and probably shouldn't be used as
* the basis for a large complex system. It is suitable for simple use cases as
* for learning.
*
* See http://datatables.net/usage/server-side for full details on the server-
* side processing requirements of DataTables.
*
* @license MIT - http://datatables.net/license_mit
*/

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

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

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

// 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 simple
// indexes
$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' => 'xx',
'pass' => 'xxxxx',
'db' => 'xxxxx',
'host' => 'xx\xxxxx'
);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 )
);

Is there something that I miss?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586
    Answer ✓

    Hi @pjustindaryll ,

    Have you modified the file config.php to point towards your DB - see here.

    Cheers,

    Colin

This discussion has been closed.