我正在努力让这个真棒JQuery plugin与SQL Server一起工作。我已经设置了PDO,因为我在其他地方使用它(使用MS Access) - 我想我现在已经安装了sql server(2008)。以下是我的联系方式:
define('DB_DSN',"odbc:Driver={SQL Server};Server=MyInstance;Database=table1;");
define('DB_USER', '');
define('DB_PASSWORD', '');
// include the jqGrid Class
require_once "php/jqGrid.php";
// include the PDO driver class
require_once "php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
$tsql = 'SELECT * FROM Trt';
// Write the SQL Query
$grid->SelectCommand = $tsql;
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('report-creator.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
"caption"=>"Report",
"rowNum"=>10,
"sortname"=>"OrderID",
"hoverrows"=>true,
"rowList"=>array(10,20,50),
));
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("stringResult"=>true));
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
我收到此错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM001]: Driver
does not support this function: driver doesn't support meta data' in
C:\wamp\www\webs\tgd\edh\php\jqGridPdo.php(1) : eval()'d code:1 Stack trace: #0
C:\wamp\www\webs\tgd\edh\php\jqGridPdo.php(1) : eval()'d code(1): PDOStatement-
>getColumnMeta(0) #1 C:\wamp\www\webs\tgd\edh\php\jqGrid.php(1) : eval()'d code(7):
jqGridDB->getColumnMeta(0, Object(PDOStatement)) #2 C:\wamp\www\webs\tgd\Front- End\report-
creator.php(31): jqGridRender->setColModel() #3 C:\wamp\www\webs\tgd\Front- End\view-
report.php(123): require_once('C:\wamp\www\web...') #4 {main} thrown in
C:\wamp\www\webs\tgd\edh\php\jqGridPdo.php(1) : eval()'d code on line 1
我感谢任何帮助 - 我无法理解这个问题。我把它缩小到这个函数:$grid->SelectCommand
- 如果我删除它没有发生错误但我不能没有这个,因为这是我的t-sql查询数据库的地方。
我可以使用PDQ->Query('SELECT * FROM table1')
查询SQL server mysql。
全部谢谢
请注意:我已编辑了表名,隐私文件路径。 :)
答案 0 :(得分:0)
看起来jqGrid使用getColumnMeta函数来枚举列,但是这个函数may be unsupported由几个驱动程序 - 在这种情况下是你的MSSQL驱动程序。
请参阅上面链接中的示例,以测试getColumnMeta是否有效。
答案 1 :(得分:0)
我为Trirand(开发人员jqGrid - ASP.NET团队的公司)工作,遗憾的是我不能帮助PHP,但我可以建议在我们自己的论坛上发布同样的问题:
在那里你会找到一个PHP jqGrid论坛,你会得到我们PHP团队的及时回复。与此同时,我会给他们写一封电子邮件并要求他们在这里提供帮助,但以防万一在那里张贴会保证给你一个答案。
干杯, 瘤胃斯坦科夫 Trirand Inc
答案 2 :(得分:0)
我无法解决这个问题,所以我切换到另一个由JQGrid人员编写的类,这个类使用了Microsoft的PHP驱动程序。这解决了我的问题,希望它有所帮助。