2010-02-22 52 views
0

我想要得到這個真棒JQuery plugin與SQL Server一起工作。我已經設置了PDO,因爲我在別處使用它(使用MS Access) - 我想我現在已經用sql server(2008)設置了它。下面是我如何連接:JQGrid和Microsoft SQL Server

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服務器mysql。

感謝所有

請注意:我已經編輯表名,對隱私文件的路徑。 :)

+0

我在粘貼的代碼塊中看不到SelectCommand。因爲它是有問題的代碼,所以如果你重新加入它會很有幫助。 –

+0

我很抱歉,我已經添加了這個。 – Abs

回答

0

我不可能解決這個問題,所以我切換到這是寫在jqGrid的傢伙,它利用微軟的PHP驅動程序的另一個類。這解決了我的問題,希望它能幫助別人。

0

看起來像jqGrid使用getColumnMeta函數枚舉列,但此功能may be unsupported由幾個驅動程序 - 在這種情況下,您的MSSQL驅動程序。

請參閱上面鏈接中的示例來測試getColumnMeta是否有效。

0

我的Trirand(開發商jqGrid的公司 - ASP.NET團隊)工作,遺憾的是不能用PHP幫助不大,但我可以建議張貼在我們自己的論壇非常相同的問題,以及:

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

那裏你會發現一個PHP的jqGrid論壇,你會得到我們的PHP團隊的及時迴應。同時我會給他們寫一封電子郵件,並要求他們在這裏幫忙,但爲了防止發佈,我們會保證給您一個答案。

乾杯, 瘤胃斯坦科夫 Trirand公司