Datatables - Json output - PostgreSQL - Returns null

会有一股神秘感。 提交于 2019-12-25 14:25:37

问题


I use datatables. I use it in conjunction with a Postgresql server. I want to take the data from the Postgresql server. I use the script found on: http://datatables.net/development/server-side/php_postgres

The script works and creates the json file. The problem is that the values on the json file are null.

This is what it returns:

{"sEcho":1, "iTotalRecords":4, "iTotalDisplayRecords":4, "aaData":[[null,null,null], [null,null,null], [null,null,null], [null,null,null]]}

Also what i don't understand is the variable $sIndexColumn (Indexed column (used for fast and accurate table cardinality)). I have set its value to the first column of my table e.g. $sIndexColumn = "'Name'";. Is this the correct use ?

Thanks in advance.


回答1:


The documentation says:

To use the code on your own server, simply change the $aColumns array to list the columns you wish to include from your database, set $sIndexColumn to a column which is indexed (for speed), $sTable to the table name, and finally fill in your database connection parameters to $gaSql.

Emphasis mine. So, $sIndexColumn should be a column name, not a quoted string. Try this:

$sIndexColumn = "Name";

Single quotes are used for strings in PostgreSQL (and most other flavors of SQL).

I'm guessing that you made the same quoting problem with your $aColumns, i.e. you did something like this:

$aColumns = array("'One'", "'Two'", "'Three'");

when you should have done something like this:

$aColumns = array("One", "Two", "Three");

You're getting three columns out but there's nothing in those columns and those column values come from here:

$row[] = $aRow[ $aColumns[$i] ];

So if $aColumns is wrong then you'll get the nulls that you're seeing.



来源:https://stackoverflow.com/questions/5859540/datatables-json-output-postgresql-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!