how to get access to a distant oracle server - php

I have never worked on an oracle database, however, now I need to use php (executed on a different server) to log into the oracle database, but it seems that there is some missing data.
what I have:
Ip address of the server and the port 1521 (ping OK from the server running my php)
data base's name
user with all privileges
the server is perfectly working (another application that is totally relying on the oracle server is perfectly working)
what I don't have:
Service Name
The used Oracle version (more likely 11g but not sure)
any kind of access to the server's system
I tried some guessed service names but I get:
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
I tried some other alternatives such using SID but still the same error with SID this time instead of service:
ORA-12505: TNS:listener does not currently know of SID given in connect descriptor
All the other solutions I found require an access to the server to run some scripts or commands, but this is impossible for my case.
The code I use :
$user = 'myUser';
$password = 'myPassword';
$database = 'MY_DB';
$conn=oci_connect($user,$password,
'(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.l.l00)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = someName)
)
)');
if ($conn) {
echo "connected";
}
else
{
echo "not connected";
}
with the error message followed by "not connected" as a result on my browser.
So, is it possible to somehow log into the database? or is it impossible?

the DBA gave me the missing information

Related

Connect Oracle wth PHP using SSH Connection

I have a client requirement to secure our application connection with the Oracle Database. Currently, we are using OCI8 PHP library (oci_connect) to connect to Oracle using credentials which we have in a config file (a kind of plain text) where we maintain all our credentials.
Now they want to improve the security by implementing some kind secure connection using SSH so communication from application to DB will be secure. I read on the internet that this is possible.
My problem is that I don't know to achieve that with PHP OCI library even if our administrator implement SSH based authentication between the application server and DB server because OCI library uses username and password to connect with DB server.
I am trying to understand if there is any way we can achieve this type of auth connections from PHP to Oracle.
I am using Oracle 12c Enterprise edition.
To answer the second part - Establishing a secure connection using SSH. We can try using Oracle Wallets. So we don't need to save any plain text password in the app server.
Try connecting from PHP to an Oracle DB using an Oracle Wallet using below steps
1 - Create a wallet (https://docs.oracle.com/cd/B19306_01/network.102/b14266/cnctslsh.htm#g1033548)
2 - Put the Oracle instant client and the wallet files somewhere on the server with PHP (for example /opt/instantclient and /opt/wallet)
3 - Start Apache with the following variables:
ORACLE_HOME=/opt/instantclient
LD_LIBRARY_PATH=/opt/instantclient
TNS_ADMIN=/opt/wallet
4 - In /opt/wallet create a tnsnames.ora files with this content:
WALLET_NAME =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = DB_IP)(PORT = DB_PORT))
(CONNECT_DATA = (SID = DB_SID))
)
where WALLET_NAME it's the name of the wallet chosen when the wallet has been created, DB_IP it's the database ip address or hostname, DB_PORT it's the db port, and DB_SID it's the sid of the database
5 - In /opt/wallet create a sqlnet.ora files with this content:
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /opt/wallet)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
6 - Restart Apache
On the PHP code side now you can connect to the database opening a connection with the following code:
$conn = oci_connect("/", "", "WALLET_NAME", null, OCI_CRED_EXT);
OCI_CRED_EXT This tells Oracle to use External or OS authentication, which must be configured in the database. The OCI_CRED_EXT flag can only be used with username of "/" and a empty password.

PHP connection to PostgreSQL, FATAL: password authentication failed for user

I am new to postgreSQL and web development and lately I tried to connect my previously created database via PHP. But things didn't worked out, I get the password authentication failed for the user postgres. I've been looking everywhere but can't find anything to solve this issue.
The database is hosted on my iMac, port 5432 and php script on heliohost.org which will be used later on to query the database.
Here is my php script:
<?php
$host = "host=127.0.0.1";
$port = "port=5432";
$dbname = "dbname=osm";
$credentials = "user=postgres password=newPassword";
$db = pg_connect( "$host $port $dbname $credentials" );
if(!$db){
echo "Error : Unable to open database\n";
} else {
echo "Opened database successfully\n";
}
?>
My pg_hba.conf looks like this :
local all postgres md5
and my postgresql.conf has : listen_addresses = localhost
I am a bit confused with this, if anyone have suggestion to get this up and running.
Thanks everyone!
If you specify 127.0.0.1 as your host, it will attempt to hit your web server at heilohost.org, not your iMac. If you really want to do this (and there are a TON of reasons why it's a terrible idea), you'll have to set listen_address=0.0.0.0, forward the port on your router to your iMac, and use your public IP address in the connection string.

Connect to MongoDB on Appfog from localhost

I'm trying to run my application on my local pc. Everything looks perfectly fine on the cloud, it works and connects to MongoDB with the code below:
$services_json = json_decode(getenv("VCAP_SERVICES"),true);
$mongo_config = $services_json["mongodb-1.8"][0]["credentials"];
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = $mongo_config["hostname"];
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = $mongo_config["port"];
// The database you want to work from (required)
$config['mongo_db'] = $mongo_config["db"];
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = $mongo_config["username"];
$config['mongo_pass'] = $mongo_config["password"];
But since I cannot get the vcap_services from my local pc, I'm using constant values for the connection to connect my app to the remote mongo server on appfog:
// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = "***";
// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = "***";
// The database you want to work from (required)
$config['mongo_db'] = "db";
// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = "***";
$config['mongo_pass'] = "***";
But when I try to execute the app through http://localhost/my-app, it gave me this error:
Unable to connect to MongoDB: Failed to connect to: ***: Connection timed out
What can be the problem?
* values are deleted for the privacy.
Did you try connecting without the VCAP variables not on localhost but the actual server? AppFog may not give authorization to connect without VCAP variables or something may be wrong on the values you manually get.
I believe this is an authorization problem. Try another cloud service if you cannot handle with it. This is not the only solution.

DB2 connection failed php

I'm trying to connect to remote DB2 via PHP. But have some problems. I've already installed IBM Application developer client.
phpinfo() output:
IBM DB2, Cloudscape and Apache Derby support enabled
Module release 1.9.4
Module revision $Revision: 327944 $
Binary data mode (ibm_db2.binmode) DB2_BINARY
Then, I've got a php file which is looking like:
$database = 'MyDB';
$user = 'db2inst1';
$password = 'mypassword';
$hostname = '1.1.1.1';
$port = 50000;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;PORT=$port;HOSTNAME=$hostname;".
"PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "connection to $database succeeded";
} else {
echo "connection to $database failed";
echo db2_conn_errormsg();
}
And trying to execute this file, I have "connection to MyDB failed", and NO visible response from db2_conn_errormsg(), which is actually making me baffled
Unfortunately, I haven't got a straight access to the remote server with database. But several months ago, when I was using other client, I succeeded to connect to exactly this database. But that time I didn't need to install IBM ADCL. That is why I can guess that problem is on this side. But even if so, I couldn't fix it.
Sorry if I duplicated some question on stackoverflow, but all answers, which I found, were unfortunately useless to me.
I'm using Apache 2.2 and PHP 5.4.
Hope you can help.
Thanks for any replies!
Are you sure you have connectivity to the server? Correct port, server, firewall rules, username, password, database name?
What is the SQL code you are receiving. Try to get the SQL code from PHP, "connection to xx failed" is your own code so it is useless to help you.
Did you install the application development client? which DB2 version are you using? ADCL is old, it was for DB2 8. Since DB2 9.7, clients have different names, and I think you need IBM Data server client in order to compile the php module. For more information, check this website: http://www-01.ibm.com/support/docview.wss?uid=swg27016878
I think you have to catalog the database server (node) and the database in the local machine with the db2 client. It seems that your PHP code uses ODBC driver, and it has to be configured locally.
Your connection string looks like an ODBC connection where as the db2_connect function in PHP needs :-
DATABASE=database;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=username;PWD=password;
It's on the PHP web page.
I have never been able to get ibm_db2 or pdo_ibm working on a remote. They work if DB2 and Apache are on the same machine (like the iSeries) but not if the host is connecting to a remote DB2.
If you read the Doctrine2 PHP drivers for each you will find they redirect to ODBC if the host is not 'localhost' or '127.0.0.1'.
This code works for me
<?php
if (!$db = odbc_connect ( "AS400", $user, $password) )
echo 'error!';
$result = odbc_exec($db, "select count(*) from $table");
while (odbc_fetch_row($result)) {
var_dump($result);
print_r($result);
echo "\n";
echo odbc_result($result, 1)."\n";
}
odbc_close($db);
AS400 is DSN name defined in ODBC.

linux php connect to Server 2008 running MS SQL Server Express

i can connect from client PC to SQL Server Express using the following creds. in mgnt sudio:
server: 192.168.44.96\sqldb
auth: windows auth
user name: domain\user
pw: 1234!
Have a LAMP server trying to connect to the above SQL server, here's what the PHP looks like:
$server = '192.168.44.96\sqldb';
$username = 'domain\user';
$password = '1234!';
$database = 'testing123';
$connection = mssql_connect($server, $username, $password);
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');
}
the page displays 'couldn't connect' and the error.log says "unable to connect ot server: 192.168.44.96".
I have also set mssql.secure_connection = On in php.ini and restarted apache2.
any thoughts?
thanks!
I can't comment on the PHP part, I only know SQL Server.
But I can tell you: That's not how Windows authentication works.
You can't use Windows authentication and then pass user name and password explicitly to the server. You need to do one of these:
Use SQL Server authentication and pass user name and password explicitly
Use Windows authentication and do not pass user name and password - you will connect automatically with the active Windows user.
Since you're using a Linux server, I'm pretty sure that you can't use Windows authentication. So you have to use SQL authentication (which needs to be enabled on a fresh SQL Server installation), and you have to create an user on the SQL Server.
If you have a default sqlexpress installation you probably need to configure your sql server to allow remote access connections.
Also I don't know if you can connect with windows auth. At your sql server you can also setup sql authentication and use uid=;pwd=.

Categories