我想创建一个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()
答案 0 :(得分:0)
我建议在深入编写代码之前尝试阅读更多关于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