我想要得到這個真棒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。
感謝所有
請注意:我已經編輯表名,對隱私文件的路徑。 :)
我在粘貼的代碼塊中看不到SelectCommand。因爲它是有問題的代碼,所以如果你重新加入它會很有幫助。 –
我很抱歉,我已經添加了這個。 – Abs