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
Related
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
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?
I want to connect to Oracle database, which requires port forwarding, using PHP.
Here is the setup.
Currently i use PuTTy to connect to Oracle Db. There i feed
Host ip: 172.XX.XX.111 port:22
Tunnel setting
Source port : L19005
Destination : 172.XX.XX.40:1521
After entering userid/password,i am able to connect sqldeveloper which needs TNS config.
Now i want to perform same activity using PHP. Here's what i have done so far
set_include_path(get_include_path().'\phpseclib');
include('Net/SSH2.php');
$ssh = new Net_SSH2('172.XX.XX.111');
if (!$ssh->login('userid', 'password')) {
exit('Login Failed');
}
$ssh->write("ssh -L19005:172.XX.XX.40:1521 172.XX.XX.111\n");
$ssh->write("password\n");
$connect='(DESCRIPTION=(ADDRESS= (PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=19005))(CONNECT_DATA = (SID = connect)))';
$conn = oci_connect('Db_username', 'Db_password', $connect);
if ($conn)
{echo 'True';}
I also used ssh2_connect function.
$connection = ssh2_connect('172.XX.XX.111', 22);
if (ssh2_auth_password($connection, 'userid', 'password'))
{
echo 'true';
}
ssh2_exec($connection,"ssh -L19005:172.XX.XX.40:1521 172.XX.XX.111","\n");
ssh2_exec($connection,"password","\n");
$connect='(DESCRIPTION=(ADDRESS= (PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=19005))(CONNECT_DATA = (SID = connect)))';
$conn = oci_connect('Db_username', 'Db_password', $connect);
if ($conn)
{echo 'True';}
In both the cases, i am getting the following error.
oci_connect(): ORA-12541: TNS:no listener in C:\xampp\htdocs\USAGE\index.php
I am using XAMPP3.2.2 with PHP5.5.
Please help. I have searched a lot but could not find anything that relates to my issue.
phpseclib doesn't do tunneling. What it looks like you're expecting it to do is for PHP to create a server on port 127.0.0.1:19005 but at that point you'd need an SSH server - not an SSH client.
My recommendation: use autossh.
I have working mssql connecting codes and them working in my another company php host but dont work when i moved new host. All codes same i dont know why connect from new host ? In new host using cpanel and php ( Hostgator ) and im looking php.ini in cpanel mssql settings looking good. my codes below under.
$usernameb ="myuser";
$passwordb = "mypass";
$databaseb = "mydb";
$host ="myhostip"
$connection = mssql_connect($host, $usernameb, $passwordb);
if (!$connection) { die('Not connected : ' . mssql_get_last_message());}
$db_selected = mssql_select_db($databaseb, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mssql_get_last_message());
} else{
}
And gives that error on my new hosting
Warning: mssql_connect(): Unable to connect to server: ip here in
Any idea ?
I am new to DB2.
$database = 'test';
$user = 'user1';
$password = 'pswd1';
$hostname = '10.250.10.10';
$port = 556;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "Connection succeeded.";
db2_close($conn);
}
else {
print($conn);
echo "Connection failed.";
die(db2_conn_errormsg());
}
all the values are correct. But connection have been failed. Plz advise me. and How to check in the PHPINFO(). whether the DB2 have been installed successfully or not.
I got the following error
Connection failed.[unixODBC][Driver Manager]Data source name not found, and no default driver specified SQLCODE=0
I'm not a PHP maven, but if you're using the ODBC driver, you probably need to catalogue the database in the ODBC driver manager. On Windows, search for ODBC in "Search Programs and Files". I'm not sure the equivalent on Linux