PHP SQLSRV Error using machine account - php

I am using SQLSRV function using windows authentication but it is using the machine account as a default. How can I change it? I want to run using HOMESBUILD\john.davis
I am running PHP 5.3.10 on WAMP Server 2.2
Error Message:
Connection could not be established.
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'HOMESBUILD\KKK-454-IAH05$'.

I had to configure the WAMP server from Services to run as different account.

Related

Connect to Azure SQL database with PHP

I try to connect to my azure database only with the provided connection string. However I just get this error message:
Error connecting to SQL Server.PDOException Object ( [message:protected] => could not find driver [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\XAMPP\htdocs\folder\Databaseconnection.php [line:protected] => 4 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\XAMPP\htdocs\folder\Databaseconnection.php [line] => 4 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => sqlsrv:server = tcp:{server}.database.windows.net,1433; Database = testdb [1] => {username} [2] => {password} ) ) ) [previous:Exception:private] => [errorInfo] => ) 1
The servername username and password is obviously changed here. I also allowed my own IP adress on the server firewall settings. Any help appriciated.
The reason is caused by that you want to use PHP PDO to connect Azure SQL Database, but the error information shows there is not a PHP driver to support SQL Azure connection.
You could reference this blog:Error connecting to SQL Server.PDOException Object (Azure).
You need to refer to the section PHP Version Support of the offical document Microsoft PHP Drivers for SQL Server Support Matrix to know what version of PHP PDO driver for Azure SQL Database is for PHP v7.4:
Please choose the suitable PHP version and SQL Server driver.
You could Download the Microsoft Drivers for PHP for SQL Server for your system. Also reference Production Release for the PHP drivers Version 5.6.0 for SQL Server.
Hope this helps.

Unable to connect to my mssql database using PHP

I see that another user had a similar question: Why can't I connect to my mssql database using PHP?
I am getting identical errors.
Array
(
[0] => Array
(
[0] => 28000
[SQLSTATE] => 28000
[1] => 18456
[code] => 18456
[2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'userName'.
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'userName'.
)
[1] => Array
(
[0] => 42000
[SQLSTATE] => 42000
[1] => 4060
[code] => 4060
[2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "DBname" requested by the login. The login failed.
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "DBname" requested by the login. The login failed.
)
[2] => Array
(
[0] => 28000
[SQLSTATE] => 28000
[1] => 18456
[code] => 18456
[2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'userName'.
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'userName'.
)
[3] => Array
(
[0] => 42000
[SQLSTATE] => 42000
[1] => 4060
[code] => 4060
[2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "DBname" requested by the login. The login failed.
[message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "DBname" requested by the login. The login failed.
)
)
I've succeeded in displaying phpinfo() for my page.
Looks like I'm running MSVC9 (Visual C++ 2008) (not sure how to update to 11 - or if I even need to).
PHP version: 5.3.28 (not sure where to look in phpinfo for driver information).
Not sure how to check that MSSQL Native Client is installed.
I'm unable to find my php.ini file. It's supposedly located in C:\Program Files (x86)\PHP\v5.3\php.ini but I don't see it.
Any help would be much appreciated.
From the error message I assume that the connection works but your credentials don't. Is it really correct to use userName as the username and DBname as the db name. Looks like you have a copy/paste problem there.
Regarding the ini file: You should see it in the phpinfo output, search for Loaded Configuration File.

Error 08001 while connecting to SQL Server by using PHP

Here is my problem, I have my connection handles like this:
$dbSrvName = 'servername';
$dbName = 'database';
$dbUser = 'user';
$dbPass = 'password';
$dbInfo = array(
'Database' => $dbName,
'UID' => $dbUser,
'PWD' => $dbPass
);
$this->dbConn = sqlsrv_connect($dbSrvName, $dbInfo);
if(!$this->dbConn)
{
die(print_r( sqlsrv_errors(), true), 1);
}
When I trigger output from sqlsrv_errors() I get the following message:
Array ( [0] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 26
[code] => 26 [2] => [Microsoft][SQL Server Native Client 10.0]Client
unable to establish connection because an error was encountered during
handshakes before login. Common causes include client attempting to
connect to an unsupported version of SQL Server, server too busy to
accept new connections or a resource limitation (memory or maximum
allowed connections) on the server. [message] => [Microsoft][SQL
Server Native Client 10.0]Client unable to establish connection
because an error was encountered during handshakes before login.
Common causes include client attempting to connect to an unsupported
version of SQL Server, server too busy to accept new connections or a
resource limitation (memory or maximum allowed connections) on the
server. ) [1] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 10054
[code] => 10054 [2] => [Microsoft][SQL Server Native Client 10.0]TCP
Provider: An existing connection was forcibly closed by the remote
host. [message] => [Microsoft][SQL Server Native Client 10.0]TCP
Provider: An existing connection was forcibly closed by the remote
host. ) [2] => Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 26
[code] => 26 [2] => [Microsoft][SQL Server Native Client 10.0]Client
unable to establish connection [message] => [Microsoft][SQL Server
Native Client 10.0]Client unable to establish connection ) [3] =>
Array ( [0] => 08001 [SQLSTATE] => 08001 [1] => 10054 [code] => 10054
[2] => [Microsoft][SQL Server Native Client 10.0]Client unable to
establish connection due to prelogin failure [message] =>
[Microsoft][SQL Server Native Client 10.0]Client unable to establish
connection due to prelogin failure ) ) [2014-12-31 08:35:25]
SQLSRV USED:
php_sqlsrv_53_ts_vc9.dll
So I am afraid the version of SQL is not compatible with this version of sqlsrv. Any ideas?
Thank you in advance and Happy New Year!
I am going to guess you are trying to remotely connect to the sql server. You need to make sure that is actually possible with your sql server configuration.
Then you need to make sure that the user account you are trying to connect with has proper permissions
Then firewall needs to be opened as well on the server...
here is a short list of things to check.
Can't Connect Remotely
Actually, it was a misunderstanding! The database that I was trying to connect to is Oracle. So the PHP library is not compatible.
Thanks anyway...

Can anyone decipher an error message I get when trying to store form data on MS SQL using php?

I attempted to connect to an Microsoft SQL database and store html form data in it using php but was unable to.
At first I attempted using the mssql syntax but realized that it was abandoned past 5.2 (I'm running 5.3). Then I attempted to connect using the sqlsrv syntax but that required a driver and editing the php.ini file -- which I did only to receive this error message pertaining to the MS SQL Native Client:
> Connection COULD NOT be establishedArray ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) )
A phpinfo file shows that sqlsrv is installed and I've deleted and reinstalled the drivers and native client twice already to no avail..........
Here is the stack:
Windows 2003 server
IIS 6 web host
local install of MS SQL 2008 (previously was attempting to connect to a remote MS SQL 2014 database
PHP version 3.1.3

PHP SQL Server 2005 Standard Edition connection timeout

I've searched through endless solutions for connection problems with PHP and SQL Server 2005 and still no luck. I'm using SQL Server 2005 Standard Edition.
Here's the code:
$server = "MYLAP01\\SQLEXPRESS";
$options = array("Database" => "test1");
$conn = sqlsrv_connect($server, $options);
if ($conn === false) die("<pre>".print_r(sqlsrv_errors(), true));echo "Successfully connected!";
sqlsrv_close($conn);
And the output:
Array
(
[0] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
[message] => [Microsoft][SQL Server Native Client 11.0]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
)
[1] => Array
(
[0] => HYT00
[SQLSTATE] => HYT00
[1] => 0
[code] => 0
[2] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired
[message] => [Microsoft][SQL Server Native Client 11.0]Login timeout expired
)
[2] => Array
(
[0] => 08001
[SQLSTATE] => 08001
[1] => -1
[code] => -1
[2] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
[message] => [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.
)
)
Fixed this by adding the port number: $server = "MYLAP01\SQLEXPRESS,1433";

Categories