我在我的 Mac 开发环境中设置了一个非常基本的 jqGrid。一切正常。网格渲染和数据加载没有问题。
当我将整个站点移到我的 Windows 机器上时,除了 jqGrid 之外,该站点工作正常。由于某种原因,网格无法访问数据。我正在使用 PDO 对象来连接和查询数据库。当我从 Mac 切换到 Windows 时,数据库凭据没有改变。我可以使用与网格分开的 PDO 对象,但是当我将对象传递给网格时,它似乎不起作用:
<?php
require_once '../Grid/jq-config.php';
// include the jqGrid Class
require_once "../Grid/php/jqGrid.php";
// include the PDO driver class
require_once "../Grid/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");
$selectCommand = "SELECT VolunteerID, FirstName, LastName, PhoneNumber, Email FROM Volunteers";
// Definition of the labels
$vLabels = array("VolunteerID"=>"Id",
"FirstName" => "First Name",
"LastName" => "Last Name",
"PhoneNumber" => "Phone Number",
"Email" => "Email");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = $selectCommand;
// set the ouput format to json
$grid->dataType = "json";
// Let the grid create the model
//$grid->setColModel(null, null, $vLabels);
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('VolunteerListGrid.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
"caption"=>"Volunteers",
"rowNum"=>10,
"sortname"=>"VolunteerID",
"hoverrows"=>true,
"rowList"=>array(10,20,50)
));
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true, true);
//$test = $conn->query($selectCommand);
//$data = $test->fetchAll(PDO::FETCH_ASSOC);
//
//echo json_encode($data);
$conn = null;
?>
我不知道是什么改变导致了这个问题。
谢谢, 贾