0

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\n";

   $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

1 Answer 1

0

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.