Could not connect with Authentication=ActiveDirectoryPassword. could not find driver - php

I have a SQL Server running the OS Windows Server 2012 R2. It is running Microsoft SQL Server 2012.
On another computer, I am running an IIS web server, and I have installed PHP version 7.2.13, and Microsoft Driver 5.3 for PHP for SQL Server.
I am trying to connect to a database on the SQL Server via PHP:
<?php
// Now connect to an Azure SQL database by setting Authentication to ActiveDirectoryPassword
$azureServer = "vgissql";
$azureDatabase = "dbo.pctProjectTracking";
$azureUsername = "myuid";
$azurePassword = "mypassword";
$connectionInfo = "Database = $azureDatabase; Authentication = ActiveDirectoryPassword;";
try
{
$conn = new PDO( "sqlsrv:server = $azureServer ; $connectionInfo", $azureUsername, $azurePassword );
echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
$conn = null;
}
catch( PDOException $e )
{
echo "Could not connect with Authentication=ActiveDirectoryPassword.\n";
print_r( $e->getMessage() );
echo "\n";
}
?>
If I try opening this php file in a browser, I get:
Could not connect with Authentication=ActiveDirectoryPassword. could not find driver
Any ideas on what could be wrong here?

Related

Problems with xampp

I can not recognize the SQL Server command in XAMPP 1.8.1 and PHP 5.4.7, this code had already used it and it worked before but now it doesn't.
I have already tried to put the php_mssql.dll dll and still don't recognize the command:
$con = mssql_connect('187.164.1.2/base','pag','123') or die('Could not connect to the server!');
mssql_select_db('aguacom') or die('Could not select a database.');
I expected it to connect to the other server's database.
You are trying to connect to MS SQL Server using MSSQL PHP extension (mssql_ functions), but this extension is not available anymore on Windows with PHP 5.3 and removed in PHP 7.0.0.
What you can do is to install PHP Driver for SQL Server (sqlsrv_ functions). You need to download:
The appropriate version of this driver - for PHP 5.4 you need version 3.2 (32-bit or 64-bit depending on the PHP version)
The appropriate ODBC driver.
Note, that MSSQL PHP extension (php_mssql.dll) and PHP Driver for SQL Server (php_sqlsrv_54_ts.dll) are two different PHP extensions.
Example using mssql_ functions:
<?php
$server = "187.164.1.2/base";
$username = "pag";
$password = "123";
$database = "aguacom";
$conn = mssql_connect($server, $username, $password);
if ($conn === false) {
echo "Unable to connect. ".mssql_get_last_message()."</br>";
exit;
} else {
echo "Connected.</br>";
}
mssql_select_db($database, $conn);
// ...
mssql_close($conn);
?>
Example using sqlsrv_ functions:
<?php
$server = "187.164.1.2/base";
$username = "pag";
$password = "123";
$database = "aguacom";
$connectionInfo = array(
"UID" => $username,
"PWD" => $password,
"Database" => $database
);
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
echo "Unable to connect. ".print_r(sqlsrv_errors(), true)."</br>";
exit;
} else {
echo "Connected.</br>";
}
// ...
sqlsrv_close($conn);
?>
you should enable mssql in xampp
things you need [download these files]: https://www.microsoft.com/en-us/download/details.aspx?id=20098
Add downloaded files in php.ini like this way
extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll
restart apache and then check
<?php
echo "<pre>";
print_r(PDO::getAvailableDrivers()); ?>
credits goes to rray

Unable to connect to Teradata from PHP WSock32 DLL

I'm trying to connect to a Teradata server using PHP, PDO and ODBC. Example code:
<?php
$username = "tuser";
$password = "tpassword";
$dbcName = "tdata";
$dsn = "odbc:Driver=Teradata;DBCName=$dbcname";
try{
$pdo = new PDO($dsn, $username, $password, [
PDO::ATTR_TIMEOUT => 20,
]);
} catch (PDOException $e) {
die($e);
}
But after executing the script, an error does appear
[WSock32 DLL] HostUnreach: Teradata server can't currently be reached
over this network.
Ping to Teradata server and telnet with Teradata server is successful. How to connect to server properly?
I'm using a Windows Server 2012 with PHP 7.

How to connect to Oracle database through my website using PHP? My data is hosted in AWS RDS

I am unable to connect to Oracle database hosted in AWS RDS through my website.
Do we need Oracle client for that? If yes, how to implement that at our end?
I have this code:
<?php
$tns = " s1234fortify.cmqwhsydjmea.us-east-1.rds.amazonaws.com ";
$db_username = "S1234";
$db_password = "S1234";
try{
$conn = new PDO("oci:dbname=".$tns,$db_username,$db_password);
} catch(PDOException $e){
echo ($e->getMessage());
}
?>
I am getting this error:
could not find driver

How to connect Microsoft SQL Database using PHP

i am trying to connect mssql database using sqlsrv_connect() php function but it's always show below fatal error.
Fatal error: Call to undefined function sqlsrv_connect().
Code:
$server = 'xx.xxx.xxx.Xxx\sqlexpress';
$username = 'uname';
$password = 'password';
$database = 'testdb';
$connectionInfo = array( "Database"=>$database, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $server, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
For this you have to download the associated driver.
The Microsoft SQL Server 2005 Driver for PHP allows PHP developers to access data in SQL Server 2005 and SQL Server 2008 databases. The driver includes support for Windows and SQL Server Authentication methods, transactions, parameter binding, streaming, metadata access, connection pooling, and error handling.
Check these links:
How to connect to MSSQL
Php Help Documnetation

Connect external MS SQL DB from Zend Framework on Linux Server

Connect external MS SQL DB from Zend Framework on Linux Server
i have Linux Server where i want my Zend Framework, and want to connect my SqlServer Database which is on Other windows hosting Sever, i have installed database on that and having Database static link to connect with that.
but how can i connect with mssql database form linx sever ?
$server='some ip add'; $username='uname'; $password='passpass';
$database ='dbname' ;
$connection = mssql_connect($server, $username, $password)or die('Could Not Connect');
echo "test2";
if($connection != FALSE){
echo "Connected to the database server OK<br />";
}
else {
die("Couldn't connect" . mssql_get_last_message());
}
if(mssql_select_db($database, $connection)){
echo "Selected $database ok<br />";
}
else {
die('Failed to select DB');
}
this code returns nothing!
any buddy connected mssql sever from linux hosting ?
I'm using multidb settings in the application.ini file since I have several different databases I'm pulling from but yes. Here is my settings from the ini file. You'll just have to make sure you have the drivers installed and setup correctly.
resources.multidb.tw.adapter = "pdo_mssql"
resources.multidb.tw.pdoType = dblib
resources.multidb.tw.charset = "utf8"
resources.multidb.tw.host = "192.168.1.111"
resources.multidb.tw.username = "username"
resources.multidb.tw.password = "passwd"
resources.multidb.tw.dbname = "database"
resources.multidb.tw.default = true
Hope that helps.
Rois

Categories