【问题标题】:PHP 7.1 connect to MSSQL NOT SQLSRVPHP 7.1 连接到 MSSQL 不是 SQLSRV
【发布时间】:2017-08-10 01:45:24
【问题描述】:

任何人都可以帮助我如何在 php 7.1 而不是 sqlsrv 中使用 mssql,因为我喜欢尝试 mssql,因为我是编程新手。

【问题讨论】:

  • 产品叫SQL Server,既不是MSSQL,也不是SQLSRV。您是否遇到连接字符串或驱动程序的问题?还是你把它和 MySQL 搞混了?

标签: sql-server php-7.1


【解决方案1】:
include 'connect.php';
$login_id = $_REQUEST['mobile_number'];
 $user_flag = $_REQUEST['user_flag'];

$con = mysqli_connect($host,$username,$password,$database);
  if (!$con) {    die("could not connect: " . mysqli_connect_error());    
}
$sql =  "select * from login_details WHERE mobile_no = '$login_id' AND user_flag = '$user_flag'";

 $result = mysqli_query($con, $sql) or die("Error in Selecting " .mysqli_error($con));

 while($row =mysqli_fetch_assoc($result)) {
     $emparray[] = $row;
 }
 echo json_encode($emparray);

 mysql_close($con);

【讨论】:

  • 这是一个关于 SQL Server 的问题,而不是 MySQL。此外,此代码非常危险,因为它使应用程序暴露于 SQL 注入攻击。使用参数化查询,而不是插值或连接
  • 检查标题 PHP 7.1 connect to MSSQL NOT SQLSRV
  • 确实,检查标题。和标签。如果有人输入 '; drop table login_details; 作为登录 ID,会发生什么。或者admin 作为用户名,' OR 1=1 作为密码。您应该使用参数化查询,而不是字符串操作
猜你喜欢
  • 1970-01-01
  • 2013-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-11
  • 1970-01-01
相关资源
最近更新 更多