【问题标题】:how to tie mssql table on jqgrid如何在 jqgrid 上绑定 mssql 表
【发布时间】:2014-09-23 08:29:07
【问题描述】:

我想制作一个 jqgrid,我想从 mssql 数据库中放 2 个表。 我做了一个 .php 但没有工作,有人可以看一下为什么不工作吗? 我是这个东西的新手..

代码>

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

我收到此错误>>

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

【问题讨论】:

  • 你确定你开启了mssql的扩展?

标签: php mysql sql sql-server jqgrid


【解决方案1】:

该错误可能是因为缺少与 MSSQL 通信的 PHP 扩展。在此处阅读 php 手册中如何安装 mssql 扩展:

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

部分

【讨论】:

    【解决方案2】:
    • 您运行的是 MySQL 服务器还是 Microsoft sql 服务器?否则 mssql_[command] 应该是 mysql_[command]。
    • 您的查询字符串在声明字符串后的行中被覆盖。它应该: $query = "选择列名"; $query .= "来自 table_test1"; 这将使 $query 等于“Select column_name From table_test”。
    • table_test1 是否存在于您的数据库中,登录时使用的凭据是否正确?
    • 例如,您的 while 循环确实会循环任何内容(请参阅:http://php.net/manual/en/control-structures.while.php)。
    • php 代码不会以 JSON 格式输出任何内容,这对于 JQGrid 从您的数据库加载数据来说是必需的。
    • jqgrid 只显示示例数据。

    我建议在深入编码之前尝试阅读有关 php 和 javascript 的更多信息。

    祝你好运。

    【讨论】:

      【解决方案3】:
      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
      

      【讨论】:

        猜你喜欢
        • 2023-03-25
        • 2013-05-04
        • 1970-01-01
        • 2013-10-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-27
        相关资源
        最近更新 更多