【问题标题】:JQGrid and Microsoft SQL ServerJQGrid 和 Microsoft SQL Server
【发布时间】:2010-02-22 12:57:08
【问题描述】:

我试图让这个很棒的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。

谢谢大家

请注意:出于隐私考虑,我已编辑表名、文件路径。 :)

【问题讨论】:

  • 我在您粘贴的代码块中没有看到 SelectCommand。因为它是有问题的代码,如果你把它重新添加进去会很有帮助。
  • 我很抱歉,我已经添加了这个。

标签: php jquery sql-server jqgrid jqgrid-php


【解决方案1】:

看起来 jqGrid 使用 getColumnMeta 函数来枚举列,但这个函数 may be unsupported 由多个驱动程序 - 在本例中是您的 MSSQL 驱动程序。

查看上面链接中的示例以测试 getColumnMeta 是否有效。

【讨论】:

    【解决方案2】:

    我在 Trirand(开发 jqGrid - ASP.NET 团队的公司)工作,很遗憾在 PHP 方面帮不上什么忙,但我也可以建议在我们自己的论坛上发布同样的问题:

    http://www.trirand.net/forum/

    在那里你会找到一个 PHP jqGrid 论坛,你会得到我们 PHP 团队的及时回复。同时,我也会给他们写一封电子邮件,并请他们在这里提供帮助,但以防万一在那里发帖会保证您得到答复。

    干杯, 鲁门斯坦科夫 三兰德公司

    【讨论】:

      【解决方案3】:

      我无法解决这个问题,所以我切换到另一个由 JQGrid 人员编写的类,该类使用 Microsoft 的 PHP 驱动程序。这解决了我的问题,希望对某人有所帮助。

      【讨论】:

        猜你喜欢
        • 2011-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-17
        相关资源
        最近更新 更多