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
我使用数据表。我将它与Postgresql服务器结合使用。我想从Postgresql服务器获取数据。我使用上面的脚本: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.
该脚本工作并创建json文件。问题是json文件上的值为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 ?
另外我不明白的是变量$ sIndexColumn(索引列(用于快速和准确的表基数))。我已将其值设置为表格的第一列,例如$ sIndexColumn =“'姓名'”;。这是正确的用法吗?
Thanks in advance.
提前致谢。
1 个解决方案
#1
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.
要在您自己的服务器上使用代码,只需更改$ aColumns数组以列出要包含在数据库中的列,将$ sIndexColumn设置为索引的列(速度),将$ sTable设置为表名,最后将数据库连接参数填入$ gaSql。
Emphasis mine. So, $sIndexColumn
should be a column name, not a quoted string. Try this:
强调我的。因此,$ sIndexColumn应该是列名,而不是带引号的字符串。试试这个:
$sIndexColumn = "Name";
Single quotes are used for strings in PostgreSQL (and most other flavors of SQL).
单引号用于PostgreSQL中的字符串(以及大多数其他SQL版本)。
I'm guessing that you made the same quoting problem with your $aColumns
, i.e. you did something like this:
我猜你用$ aColumns引用了相同的引用问题,即你做了类似这样的事情:
$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 null
s that you're seeing.
因此,如果$ aColumns是错误的,那么你将获得你所看到的空值。
#1
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.
要在您自己的服务器上使用代码,只需更改$ aColumns数组以列出要包含在数据库中的列,将$ sIndexColumn设置为索引的列(速度),将$ sTable设置为表名,最后将数据库连接参数填入$ gaSql。
Emphasis mine. So, $sIndexColumn
should be a column name, not a quoted string. Try this:
强调我的。因此,$ sIndexColumn应该是列名,而不是带引号的字符串。试试这个:
$sIndexColumn = "Name";
Single quotes are used for strings in PostgreSQL (and most other flavors of SQL).
单引号用于PostgreSQL中的字符串(以及大多数其他SQL版本)。
I'm guessing that you made the same quoting problem with your $aColumns
, i.e. you did something like this:
我猜你用$ aColumns引用了相同的引用问题,即你做了类似这样的事情:
$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 null
s that you're seeing.
因此,如果$ aColumns是错误的,那么你将获得你所看到的空值。