我有一个适用于PHP5.6.6的Datatables/ajax工作表,它在PHP7上出现错误,并且没有填充

我有一个适用于PHP5.6.6的Datatables/ajax工作表,它在PHP7上出现错误,并且没有填充,php,jquery,mysql,ajax,datatables,Php,Jquery,Mysql,Ajax,Datatables,目前,我有一个简单的员工电话簿页面,它是从MySQL表->员工中填充的。我使用Datatables通过简单的AJAX/JQuery/JSON调用和返回来格式化和引入数据,我还使用Datatables、引导和格式化页面输出 在他们的网站上,我在Document.ready区域中设置了各种参数 <script type="text/javascript" class="init"> $(document).ready(function() { $('#employee').dataTa

目前,我有一个简单的员工电话簿页面,它是从MySQL表->员工中填充的。我使用Datatables通过简单的AJAX/JQuery/JSON调用和返回来格式化和引入数据,我还使用Datatables、引导和格式化页面输出

在他们的网站上,我在Document.ready区域中设置了各种参数

<script type="text/javascript" class="init">

$(document).ready(function() {
$('#employee').dataTable( {
 "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
 "aProcessing": true,
 "aServerSide": true,
  "ajax": "assets/server-response-emp.php",

     dom: 'Blfrtip',buttons: [

            {
                extend: 'print',
                customize: function ( win ) {
                    $(win.document.body)
                        .css( 'font-size', '7pt')
                        .prepend(
                            '<img src="" style="position:absolute; top:0; left:0;" />'
                        );
                     $(win.document.body).find( 'table' )
                        .addClass( 'compact' )
                        .css( 'font-size', 'inherit' );
                }
            },
           {    extend: 'pdfHtml5',
                orientation: 'landscape',
                pageSize: 'Letter',
                title: 'Emplopee Directory'
            }

            ]
    } );
    } );

    </script>

$(文档).ready(函数(){
$(#employee')。数据表({
“长度菜单”:[[10,25,50,-1],[10,25,50,“全部”],
“处理”:正确,
“服务器端”:没错,
“ajax”:“资产/服务器响应emp.php”,
dom:'Blfrtip',按钮:[
{
扩展:“打印”,
自定义:功能(win){
$(win.document.body)
.css('font size','7pt')
.预编(
''
);
$(win.document.body).find('table')
.addClass('compact')
.css('font size','inherit');
}
},
{扩展:'pdfHtml5',
定位:'景观',
页面大小:'字母',
标题:“Emplopee目录”
}
]
} );
} );
同样从他们的例子来看,我使用的是基本的php

<?php
    /*
     * Script:    DataTables server-side script for PHP and MySQL
     * Copyright: 2010 - Allan Jardine, 2012 - Chris Wright
     * License:   GPL v2 or BSD (3-point)
     */

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

    /* Array of database columns which should be read and sent back to DataTables. Use a space where
     * you want to insert a non-database field (for example a counter or static image)
     */
    $aColumns = array('emp_no', 'last_name', 'first_name',  'email', 'phone');

    /* Indexed column (used for fast and accurate table cardinality) */
    $sIndexColumn = "last_name";

    /* DB table to use */
    $sTable = "employee";

    /* Database connection information */
    $gaSql['user']       = "*******";
    $gaSql['password']   = "*******";
    $gaSql['db']         = "*******";
    $gaSql['server']     = "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
     */

    /*
     * Local functions
     */
    function fatal_error ( $sErrorMessage = '' )
    {
        header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' );
        die( $sErrorMessage );
    }


    /*
     * MySQL connection
     */
    if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password']  ) )
    {
        fatal_error( 'Could not open connection to server' );
    }

    if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) )
    {
        fatal_error( 'Could not select database ' );
    }


    /*
     * Paging
     */
    $sLimit = "";
    if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
    {
        $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
            intval( $_GET['iDisplayLength'] );
    }


    /*
     * Ordering
     */
    $sOrder = "";
    if ( isset( $_GET['iSortCol_0'] ) )
    {
        $sOrder = "ORDER BY  ";
        for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
        {
            if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
            {
                $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
                    ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
            }
        }

        $sOrder = substr_replace( $sOrder, "", -2 );
        if ( $sOrder == "ORDER BY" )
        {
            $sOrder = "";
        }
    }


    /*
     * Filtering
     * NOTE this does not match the built-in DataTables filtering which does it
     * word by word on any field. It's possible to do here, but concerned about efficiency
     * on very large tables, and MySQL's regex functionality is very limited
     */
    $sWhere = "";
    if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
    {
        $sWhere = "WHERE (";
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
            {
                $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
            }
        }
        $sWhere = substr_replace( $sWhere, "", -3 );
        $sWhere .= ')';
    }

    /* Individual column filtering */
    for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
        {
            if ( $sWhere == "" )
            {
                $sWhere = "WHERE ";
            }
            else
            {
                $sWhere .= " AND ";
            }
            $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
        }
    }


    /*
     * SQL queries
     * Get data to display
     */
    $sQuery = "
        SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
        FROM   $sTable
        $sWhere
        $sOrder
        $sLimit
    ";
    $rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );

    /* Data set length after filtering */
    $sQuery = "
        SELECT FOUND_ROWS()
    ";
    $rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
    $aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
    $iFilteredTotal = $aResultFilterTotal[0];

    /* Total data set length */
    $sQuery = "
        SELECT COUNT(".$sIndexColumn.")
        FROM   $sTable
    ";
    $rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
    $aResultTotal = mysql_fetch_array($rResultTotal);
    $iTotal = $aResultTotal[0];


    /*
     * Output
     */
    /*
    $output = array(
        "sEcho" => intval($_GET['sEcho']),
        "iTotalRecords" => $iTotal,
        "iTotalDisplayRecords" => $iFilteredTotal,
        "aaData" => array()
    );
    */

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
        $row = array();
        for ( $i=0 ; $i<count($aColumns) ; $i++ )
        {
            if ( $aColumns[$i] == "version" )
            {
                /* Special output formatting for 'version' column */
                $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
            }
            else if ( $aColumns[$i] != ' ' )
            {
                /* General output */
                $row[] = $aRow[ $aColumns[$i] ];
            }
        }
        $output['aaData'][] = $row;
    }

    echo json_encode( $output );
?>

最初的MySQL扩展在PHP5.5中被贬低,在PHP7中被删除,因此您的
MySQL\uU*
函数可能会抛出错误。请参阅。通过插入
错误报告来抑制警告(E\u ALL ^E\u已弃用)作为PHP脚本的第一行。我很久以前就停止使用datatables PHP了。假设您将一个格式良好的JSON对象传递到AJAX中,那么就没有理由这样做。我将重点介绍如何使用PHP创建此对象,并将其传递到
数据
参数中。创建一个新的datatables JS构建,并包含所有您想要的插件,包括过滤等。您可以从PHP中获取所有这些,这将删除您的错误。让PHP只创建数据对象。在这里创建您的构建:感谢所有人的帮助。这个错误实际上只是没有对象的返回。所以我认为jonmrich的方法将是最好的方法。我实际上只是将datatables用作一个很好的格式化程序。我可以换成硬CSS。至于MySQL扩展。。啊,好啊!:)我可能没有看过新的工具集。最初的MySQL扩展在PHP5.5中被贬低,在PHP7中被删除,所以你的
MySQL.*
函数可能会抛出错误。请参阅。通过插入
错误报告来抑制警告(E\u ALL ^E\u已弃用)作为PHP脚本的第一行。我很久以前就停止使用datatables PHP了。假设您将一个格式良好的JSON对象传递到AJAX中,那么就没有理由这样做。我将重点介绍如何使用PHP创建此对象,并将其传递到
数据
参数中。创建一个新的datatables JS构建,并包含所有您想要的插件,包括过滤等。您可以从PHP中获取所有这些,这将删除您的错误。让PHP只创建数据对象。在这里创建您的构建:感谢所有人的帮助。这个错误实际上只是没有对象的返回。所以我认为jonmrich的方法将是最好的方法。我实际上只是将datatables用作一个很好的格式化程序。我可以换成硬CSS。至于MySQL扩展。。啊,好啊!:)我可能只是没有看到新的工具集。