【发布时间】:2019-02-19 18:46:55
【问题描述】:
我确定有人问过这个问题。我已经搜索了答案,但我似乎找不到它。我有这段代码可以将数据从 PHP 连接到 MS Sql 数据库中。它不工作。
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<?php
//Session Start
session_start();
include '/includes/dbconn.mssql.php';
ini_set('display_errors','On');
?>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div>
</div>
</body>
<?php
$sql = "INSERT INTO
agents(fname,lname,date,dl1,ul1,lat1,jit1,dl2,ul2,lat2,jit2,dl3,ul3,lat3,jit3,UCN,ISP,IP,mmake,mmodel,[user],pass,email,winver,modem,mon1mk,mon1mdl,mon2mk,mon2mdl,headset,hmake,hmodel,webcam,prospect,[current],planul,plandl,station) "
. "VALUES('Janice','Smith','2/15/2019','10','10','1','1','10','10','1','1','10','10','1','1','333689','Xfinity','10.0.0.1','Ubee','100','admin','password','jane.smith@companyinc.com','null','null','Acer','100','AOC','5','1','Plantronic','54','1','0','1','150','50','28')";
// $sql = "INSERT INTO agents(fname,lname,date,dl1,ul1,lat1,jit1,dl2,ul2,lat2,jit2,dl3,ul3,lat3,jit3,UCN,ISP,IP,mmake,mmodel,user,pass,email,winver,modem,mon1mk,mon1mdl,mon2mk,mon2mdl,workspace,monitor1,monitor2,headset,hmake,hmodel,webcam,prospect,current,planul,plandl,station) VALUES('$fname','$lname','$date','$dl1','$ul1','$lat1','$jit1','$dl2','$ul2','$lat2','$jit2','$dl3','$ul3','$lat3','$jit3','$UCN','$ISP','$IP','$mmake','$mmodel','$user','$pass','$email','$winver','$modem','$mon1mk','$mon1mdl','$mon2mk','$mon2mdl','$workspace','$monitor1','$monitor2','$headset','$hmake','$hmodel','$webcam','$prospect','$current','$planul','$plandl','$station')";
$result = sqlsrv_query($conn,$sql);
$echo = sqlsrv_rows_affected;
if(!$result) {
echo 'Your code failed. $echo';
}
else {
echo 'Success! $echo';
}
?>
</html>
当我在 Edge 中运行代码时,它会显示
致命错误:在 .... 第 34 行调用未定义函数 sqlsrv_query()
第 34 行是
$result = sqlsrv_query($conn,$sql);
我做错了什么?
【问题讨论】:
-
您没有任何与
undefined function sqlsrv_connect相关的错误吗?你应该在 sqlsrv_query 之前得到它。确保 sqlsrv 扩展 is installed -
这也很可疑:
include '/includes/dbconn.mssql.php';因为它暗示includes目录位于文件系统根目录,而不是相对于 PHP 中的其他目录。您的系统中可能就是这种情况,但似乎不太可能并且非常罕见。并且可以解释为什么 no 没有从sqlsrv_connect()得到先前的错误。 -
你已经打开了 display_errors 这很好,也就是在该行之前设置
error_reporting(E_ALL);
标签: php html sql-server database