I am currently using PHP 5.2, with Microsoft Server 2008 R2, and using sqlsrv, with SQL native client 10.0.
I have changed the php extension to include extension=php_sqlsrv_52_ts_vc6.dll and have done the necessary changes to php.ini.
The php.info page also shows the sqlsrv has been installed successfully, but I am not sure why when I try to use sqlsrv command, it is unable to connect to SQL server. This is my codes.
<?php
$myServer = "MYSERVER\SQLEXPRESS";
$myUser = "sa";
$myDB = "Form";
$conInfo = array('Database'=>$myDB, 'UID'=>$myUser);
$conn = sqlsrv_connect( $myServer, $conInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
It shows [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'sa'. [message]. Could someone be kind enough to tell me what seems to go wrong?
I need the answer urgently.Thank you.
Try with this -
<?php
$myServer = "MYSERVER\SQLEXPRESS";
$myUser = "sa";
$myDB = "Form";
$conInfo = array('Database'=>$myDB, 'UID'=>$myUser, 'PWD'=>'');
$conn = sqlsrv_connect( $myServer, $conInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
Related
I need to show some fields from another database (SQL Server), in my form in Drupal 7, but don't need disconnect from MySql.
I'm creating a custom module in Drupal 7 and in this module create connect to SQL Server, but this doesn't work, can anyone help me?
<?php
$serverName = "test"; //serverName\instanceName
$connectionInfo = array( "Database"=>"testdb", "UID"=>"user", "PWD"=>"qwer");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
I have loaded the SQL drivers in php/etc folder and also have edited path in php.ini. I can see sqlsrv in php info as well.
This is the code that I am using to connect to SQL Server on another server.
I tried server name "10.10.10.38:1433" this also nothing worked for me.
$serverName = "10.10.10.38,1433";
$connectionInfo = array( "Database"=>"DBNAME", "UID"=>"USERNAME", "PWD"=>"PASSWORD");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn) {
echo "Connection established.<br />";
} else {
echo "Connection could not be established.<br />";
die (print_r( sqlsrv_errors(), true));
}
But I am getting following error:
Please help to resolve the issue.
Have you enabled pdo_sqlsrv ?
Have you installed ODBC drivers?
https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15
After installing the right ODBC drivers as Maxi Malvido told you you can use a PDO connection:
<?php
$conn = new PDO('sqlsrv:Server=yourserver; Database=test', 'login', 'password');
if ($conn)
{
echo "Connection established";
}
else {
echo "Connection not established";
}
?>
Im trying to use MS SQL server with PHP in MAMP and I get an error 500.
Below is the php code that Im using.
I learned today that I have to instal a driver but I don't know how to do it in MAMP.:
https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-on-iis/install-the-sql-server-driver-for-php
Any idea? many thanks,
<?php
$serverName = "MPR01\SQLEXPRESS"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"Fund_Lib");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
With the error message in hand I just found the answer in this post:
https://es.stackoverflow.com/questions/55679/fatal-error-call-to-undefined-function-sqlsrv-connect
I have a website locally hosted on my computer. My server is using PHP 5.6.21. I am trying to connect to a SQL Database on another computer Microsoft SQL Server 2000.
I have installed the PHP extensions, PHP_sqlsrv_56_ts and PHP_sqlsrv_56_nts. I have enabled them in the php.ini:
extension=php_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_ts.dll
I have tried to connect using this:
<?php
$serverName = "serverName\sqlexpress, 1542"; //serverName\instanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
And I tried using this:
<?php
$connection_string = 'DRIVER={SQL Server};SERVER=<Hector\SQLEXPRESS>;DATABASE=tempdb';
$user = 'sqltestclient';
$pass = 'paSSword';
$connection = odbc_connect( $connection_string, $user, $pass ) or die("Unable to connect to server");
echo $connection.' '.$user.' '.$pass;
?>
But neither work, the top wont load the page and the bottom just sasys unable to connect.
Im not sure what Im doing wrong
I was able to solve my problem using the information from this link.
http://www.techrepublic.com/article/access-microsoft-sql-server-2000-using-php/
May be this will help:
$serverName = "SERVER\\NAME";
$connInfo = array("Database"=>"stockdata");
$conn = sqlsrv_connect($serverName, $connInfo);
if($conn){
$sql = "SELECT * FROM users";
$res = sqlsrv_query($conn,$sql);
$arr = sqlsrv_fetch_array($res,SQLSRV_FETCH_ASSOC);
print_r($arr);
}else{
echo "Connection could not be established.<br />";
die( print_r(sqlsrv_errors(), true));
}
If you are using Windows Authentication no need to provide credentials ,otherwise you will get exception
I've been doing a project in PHP(xampp) which requires to connect to a SQL Server database.
I've already done things like downloading and installing SQLSRV30.exe in C:\xampp\php\ext folder and creating a simple program which determine whether the program is already connected or not but still couldn't figure it out the problem that i encountered.
$server = "IDEA-PC\SQLEXPRESS";
$dbGet = array("Database"=>"LogboxDB");
$con = sqlsrv_connect($server, $dbGet) or die (sqlsrv_error());
if(!$con)
{
die(print_r(sqlsrv_errors(), true));
}
else
{
echo 'Connected';
}
Here is my error.
Fatal error: Call to undefined function sqlsrv_connect();
How can I get rid of this problem?
You need to enable the extension support to use the MSSQL server in PHP. It can be enabled by editing the php.ini as follow.
extension=php_sqlsrv.dll
You can donwload the package from http://docs.gurock.com/testrail-admin/howto-installing-sqlsrv
Try This
$serverName = "192.168.1.223, 1433"; //serverName\instanceName - change it as yours
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.
$connectionInfo = array( "Database"=>"LogboxDB", "UID"=>"username", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}