-1
I’m trying to connect a Sqlserver 2012 using php 5.3 with the driver sqlsrv
, however even managing to connect with SQL management studio by php always return me the error
[Microsoft][SQL Server Native Client 11.0][SQL Server]'.
Code:
sqlsrv_connect('DANIEL-PC\SQLEXPRESS', array(
'UID' => 'sa',
'PWD' => '123456',
'Database' => 'CTe'
));
var_dump(sqlsrv_errors());
And that’s always the way out
array
0 =>
array
0 => string '28000' (length=5)
'SQLSTATE' => string '28000' (length=5)
1 => int 18456
'code' => int 18456
2 => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Falha de logon do usuário 'sa'.' (length=85)
'message' => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Falha de logon do usuário 'sa'.' (length=85)
1 =>
array
0 => string '42000' (length=5)
'SQLSTATE' => string '42000' (length=5)
1 => int 4060
'code' => int 4060
2 => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Não é possível abrir o banco de dados "Phoros_CTe" solicitado pelo logon. Falha de logon.' (length=143)
'message' => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Não é possível abrir o banco de dados "Phoros_CTe" solicitado pelo logon. Falha de logon.' (length=143)
2 =>
array
0 => string '28000' (length=5)
'SQLSTATE' => string '28000' (length=5)
1 => int 18456
'code' => int 18456
2 => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Falha de logon do usuário 'sa'.' (length=85)
'message' => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Falha de logon do usuário 'sa'.' (length=85)
3 =>
array
0 => string '42000' (length=5)
'SQLSTATE' => string '42000' (length=5)
1 => int 4060
'code' => int 4060
2 => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Não é possível abrir o banco de dados "CTe" solicitado pelo logon. Falha de logon.' (length=143)
'message' => string '[Microsoft][SQL Server Native Client 11.0][SQL Server]Não é possível abrir o banco de dados "CTe" solicitado pelo logon. Falha de logon.' (length=143)
By default SQL Server disables the user
sa
and only authentication by Windows user accounts is enabled. Certainty: Is the user enabled? Not using SSMS (SQL Server Management Studio) in Windows authentication mode? The server authentication type is set tomixed
?– gmsantos
I believe this should be your dev environment. In the production environment nay use the user
sa
. It is equivalent toroot
Mysql and this is a huge security breach in your application!– gmsantos
the user is enabled and the authentication mode this Mixed.
– Daniel Lemes
@gmsantos, why?
– ptkato
@Patrick some risks are: exposure of user authentication with all the privileges in the SQL Server instance, access to improper information, loss of traceability (who sees what?) . Suppose your application has a SQL Injection gap, which you think it can cause more impact: a credential with only the necessary permissions in a specific schema/database, or the user who can do everything in the database instance?
– gmsantos