如何在jqgrid上绑定mssql表

时间:2014-09-23 08:29:07

标签: php mysql sql sql-server jqgrid

我想创建一个jqgrid,我想从mssql数据库中放入2个表。 我做了一个.php但没有工作,有人可以看一看为什么选择工作? 我对这件事情有兴趣..

代码和GT;

<?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代码&gt;

<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>

我收到此错误&gt;&gt;

致命错误:在第8行的C:\ xampp \ htdocs \ Connect.php中调用未定义的函数mssql_connect()

3 个答案:

答案 0 :(得分:0)

  • 您运行的是MySQL服务器还是Microsoft SQL Server?否则mssql_ [command]应该是mysql_ [command]。
  • 声明字符串后,您的查询字符串会在行中被覆盖。这应该: $ query =&#34;选择column_name&#34 ;; $ query。=&#34;来自table_test1&#34 ;; 这将使$ query等于&#34;选择column_name来自table_test&#34;。
  • table_test1是否存在于您的数据库中并且是否使用凭据进行正确登录?
  • 你的while循环确实循环任何东西(参见:http://php.net/manual/en/control-structures.while.php)作为例子。
  • php代码不会输出任何内容作为JSON,JQGrid从数据库加载数据应该是必需的。
  • jqgrid仅显示示例数据。

我建议在深入编写代码之前尝试阅读更多关于php和javascript的内容。

祝你好运。

答案 1 :(得分:0)

该错误可能是由于缺少与MSSQL通信的PHP扩展而引起的。在这里阅读如何在php手册中安装mssql扩展:

http://php.net/manual/en/mssql.setup.php - 尤其是要求部分安装

答案 2 :(得分: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