2014-09-23 70 views
0

我想製作一個jqgrid,並且我想從mssql數據庫中放置兩個表格。 我做了一個.php但沒有工作,有人可以看秒爲什麼不工作? 我對這個東西neewbie ..如何在jqgrid上綁定mssql表格

代碼>

<?php 
$myServer = "localhost"; 
$myUser = "root"; 
$myPass = ""; 
$myDB = "test"; 

//connection to the database 
$dbhandle = mssql_connect($myServer, $myUser, $myPass) 
    or die("Couldn't connect to SQL Server on $myServer"); 

//select a database to work with 
$selected = mssql_select_db($myDB, $dbhandle) 
    or die("Couldn't open database $myDB"); 

// Declare the SQL query for Database 
$query = "Select [Column 1]"; 
$query = "From table_test1"; 

//Execute the SQL query and return records 
$result = mssql_query($query); 

//Display the results 
while($row = mssql_fetch_array($result)) 


//Close the connection 
mssql_close($dbhandle); 
?> 

和jqGrid的代碼>

<html> 
<head> 
    <title id='Description'>Expedio Weekly Tickets</title> 
    <script src="js/jquery-1.11.0.min.js" type="text/javascript"></script> 
    <script src="js/i18n/grid.locale-en.js" type="text/javascript"></script> 
    <script src="js/jquery.jqGrid.min.js" type="text/javascript"></script> 
    <link rel="stylesheet" type="text/css" media="screen" 
    href="Style/redmond/jquery-ui.min.css"/>  
    <script type="text/javascript"> 

     $(document).ready(function(){ 

      $("#grid").jqGrid({ 
      data: mydata, 
      datatype: 'local', 
      width: 1320, 
      colNames: ["A", "B", "C"], 
      colModel: 
        [ 
      {name: 'A', index: 'A', key: true, width:10}, 
      {name: 'B', index: 'B', width:20}, 
      {name: 'C', index: 'C', width:40} 
        ], 
      pager: '#pager', 
      sortname: 'id', 
      viewrecords: true, 
      sortorder: "asc", 
      caption: "Test" 
      }); 
     }); 


    </script> 
</head> 
<body> 
<table id="grid"></table> 
<div id="pager"></div> 
</body> 
</html> 

我得到這個錯誤>>

致命錯誤:調用未定義函數mssql_connect()在C:\ xampp \ htdocs \ Connect.php上線8

+0

你確定你已經在擴展MSSQL切換? – Santhos 2014-09-23 08:44:19

+0

你是什麼意思? – boggdan 2014-09-23 08:45:08

回答

0
  • 您是否正在運行MySQL服務器或Microsoft SQL Server?否則mssql_ [command]應該是mysql_ [command]。
  • 在聲明字符串後,您的查詢字符串被覆蓋在行中。它應該: $ query =「Select column_name」; $ query。=「From table_test1」; 這將使$ query等於「從column_test選擇列名」。
  • table_test1是否存在於您的數據庫中並且是登錄正確的使用憑據?
  • 您的while循環會循環執行任何操作(請參閱:http://php.net/manual/en/control-structures.while.php)。
  • php代碼不會輸出任何JSON,它應該是JQGrid從您的數據庫加載數據所必需的。
  • jqgrid只顯示示例數據。

我建議嘗試閱讀一些關於PHP和JavaScript深入潛水編碼之前。

祝你好運。

0
Usee the Adodb class to connect to sqlserver 2008: 
The find here: 

http://adodb.sourceforge.net/ 

Example Usage: 
include ('adodb/adodb.inc.php "); 
$ Conn = & ADONewConnection (odbc_mssql); 
/* Create a connection object to SQL Server */
$ Data = "Driver = {SQL Server}; Server = 192.168.1.28; Database = master;" 
/* We define our DSN */
$ Connection-> Connect ($ data, 'db_user', 'pass_dbuser'); 
/* Make the connection to the corresponding parameters */
$ Sql ​​= "SELECT count (*) as count FROM TABLEBD"; 
/* SQL Reference is made to know how many records are displayed */
$ Result = & $ conn-> Execute ($ sql); 
if (! $ result) 
    print $ conn-> ErrorMsg(); 
// Declare an if in case your query has not been executed well, to show us the error 
else { 
    if ($ result-> EOF) {$ count = $ result-> fields [0];} 
    // Echo "The number of records is:" $ count;. 

} 
/* We close objects, this step is optional, but optimized our code */
$ Result-> Close(); 
$ Connection-> Close(); 

Good Look 

fastdid 
+0

您的代碼有很多錯誤,無法運行。 – 2015-03-17 21:29:43