dongzaocheng3214 2014-11-28 07:38
浏览 62
已采纳

SQL Server SQL身份验证

I want to connect to a sql Server.. Only it won't work.

I granted a user and role enough permissions. But what am I doing

<?php
   $serverName = "LERAARSKAMER01\SQLEXPRESS"; 
   $database = "sqlservertest";

   // Get UID and PWD from application-specific files. 
   $uid = "sqlAdmin";
   $pwd = "tester";

   try {
      $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); 
      $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 
   }

   catch( PDOException $e ) {
      die( "Error connecting to SQL Server" ); 
   }

   echo "Connected to SQL Server
";

   $query = 'select * from dbo.users'; 
   $stmt = $conn->query( $query ); 
   while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){ 
      print_r( $row ); 
   }

   // Free statement and connection resources. 
   $stmt = null; 
   $conn = null; 
?>

This is a screenshot of the server...

What is wrong?

  • 写回答

1条回答 默认 最新

  • dpub33855 2014-11-28 09:12
    关注

    After searching for a while I found I have to set sql Authentication on.

    Microsoft SQL Managment Studio --> Database (right click-> properties->security)

    Then I enabled sa, changed the password and settings with this (password policy,...). It works also with sqlAdmin (the other user). Just with the same code..

    USE Master
    GO
    ALTER LOGIN test_must_change WITH PASSWORD = ‘samepassword’
    GO
    ALTER LOGIN test_must_change WITH
          CHECK_POLICY = OFF,
          CHECK_EXPIRATION = OFF;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?