server_processing.php blank page if I include more 2 field!

server_processing.php blank page if I include more 2 field!

asleasle Posts: 75Questions: 24Answers: 0
edited August 22 in Free community support

I have set up server processing like I have done many times before. So I am testing the json output here:
Retracted
but when I add more than 2 fields I get a blank page. No errors at all. I have tried to log errors but nothing. How can I find out what is wrong when there is no data to debug?

See below, when I remove any comment for any field after the "garantinr" - I get a blank page. Now the test link is showing only 2 fields since I have commented out all fields from "2".

<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
 */
// DB table to use
$table = 'MY_TABLE'; 

// 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' => 'id',            'dt' => 0),
        array( 'db' => 'garantinr',     'dt' => 1),
/*      array( 'db' => 'forhandler',        'dt' => 2 )
        array( 'db' => 'kunde_enavn',       'dt' => 3 ),
        array( 'db' => 'kunde',             'dt' => 4,
                'formatter' => function( $d, $row ) {
                    // remove white spaces
                    return str_replace(' ', '', $row[4].' '.$row[3]);
                    }
                ),
        array( 'db' => 'kunde_postnr',          'dt' => 5 ),
        array( 'db' => 'kunde_postnr',          'dt' => 6 ),
        array( 'db' => 'pumpemod',      'dt' => 7),
        array( 'db' => 'varenummer',        'dt' => 8),
        array( 'db' => 'mont_navn',     'dt' => 9),
        array( 'db' => 'reg_dato',  'dt' => 10 ),
        array( 'db' => 'ordrenummer',       'dt' => 11 ), */
);

// SQL server connection information
$sql_details = array(
    'user' => 'USER',
    'pass' => 'PASSWORD',
    'db'   => 'DB',
    'host' => 'localhost' 
);

//print_r($columns);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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 )
);

This question has accepted answers - jump to:

Answers

  • asleasle Posts: 75Questions: 24Answers: 0

    Hi, I solved it from this post
    https://datatables.net/forums/discussion/40184/server-side-processing-empty-json
    but I have not had to add the charset before to the server script. I think all my databases are UTF-8. Is this something new then and do I have to add this to every connection when using server-script?

  • allanallan Posts: 56,837Questions: 1Answers: 9,033 Site admin
    Answer ✓

    No, the need for the charset is entirely down to the configuration of the database and the PHP / database connection. If you don't need it - great :)

    Allan

  • asleasle Posts: 75Questions: 24Answers: 0
    edited September 7

    Hi Allan, I checked the other mysql databases that worked without the charset settings in server_processing.php and they are all utf8mb4_general_ci while this DB I had problems with has latin1_swedish_ci (old DB, must be 10 years old at least). I am using Norwegian language and this is what made the trouble since it is a UTF-8 charset.

    Now I understand the problem and solution but what frustrated me was that I got no error feedback, just a blank page. Lucky I found that post. Otherwise this should be noted somewhere in the server-side-processing section maybe if others encounter this problem.

    So just to clarify if your server script seems ok, no errors, but your page is blank. Check if your DB is not some UFT-8 variant. If you can not change that try this:
    in server script add the charset:

    // SQL server connection information
    $sql_details = array(
        'user' => '-',
        'pass' => '-',
        'db'   => '-',
        'host' => 'localhost',
        'charset' => 'utf8'
    );
    

    Then in the ssp.class.php change this line
    "mysql:host={$sql_details['host']};dbname={$sql_details['db']}",
    to
    "mysql:host={$sql_details['host']};dbname={$sql_details['db']};charset={$sql_details['charset']}",

    Now I tried to change the database charset and all the tables to utf8mb4_unicode_ci but this still does not work (blank page) without the charset fix. I wonder why?

  • allanallan Posts: 56,837Questions: 1Answers: 9,033 Site admin
    Answer ✓

    Your PHP sever is probably set up to not display errors. Which is correct for production servers as the error messages can be security risks (containing passwords, etc).

    When debugging I tend to put:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    at the top of the loaded page to force errors to display. Or you could check the server's error logs.

    Allan

Sign In or Register to comment.