PHP PDO OCI TNS adatpter error (c:635) - php

I'm browsing the web for two days in 3 languages, but unfortunately couldn't find an answer (checked the questions here of course, but the one identical was unanswered).
There's a virtual server with apache 2.4,php 5.6.7,oracle instant client 12_1 (32 bit). After a few restarts and ini configuration I managed to use PDO odbc and plain oci_connect(). BUT when I try PDO OCI I get this error message:
Error!: SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-12560:
TNS:protocol adapter error (ext\pdo_oci\oci_driver.c:635)
The TNS name I set was successfully used in SQL developer to connect.
I'm fairly new to this environment so please ask for the information you might need.

Try something like this.
$conn = new Pdo("oci:dbname=(DESCRIPTION = (ADDRESS_LIST = (
ADDRESS = (PROTOCOL = TCP)
(HOST = {$params['host']} )
(PORT = {$params['port']} )
))
(CONNECT_DATA = (SID = {$params['servicename']})
)); charset=AL32UTF8",
$params['user'],
$params['password']
);

Related

cURL error [0]: Failed to connect to 127.0.0.1 port 8545: Connection refused

I am using laravel package(furqansiddiqui/erc20-php) for erc20 token transfer, But i am getting error when execute the code
$geth = new EthereumRPC('127.0.0.1', 8545);
$erc20 = new ERC20($geth);
$token = $erc20->token("0x05f4a42e251f2d52b8ed15e9fedaacfcef1fad27");
var_dump($token->name()); // string(7) "Zilliqa"
Make sure to run geth by --rpc parameter
geth --rpc
As easier way to connect to Ethereum network, you can use https://infura.io
Infura support mainnet and testnets (rinkeby, ropsten, kovan, goerli), thats good for development.

Error connecting to an SQL data source when using sqlsrv_connect()

I'm fairly new to using PHP to connect to a SQL Database and I am having an issue where I receive this error message, when trying to connect to a database via sqlsrv_connect():
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I've followed the instructions found here and have placed this extension; php_sqlsrv_53_nts.dll, into the php.ini file. Phpinfo() shows sqlsrv as enabled on the web server but I still receive the same error when trying to connect to the data source.
Below is the code I am using:
$db_server = 'tcp:192.168.0.1';
$db_credentials = array('UID' => 'Domain\Username', //SQL Server UID
'PWD' => 'Password', //SQL PW
'Database' => 'ThisDatabase', //Name of the database
'CharacterSet' => 'UTF-8',
'ConnectionPooling' => 'False',
'LoginTimeout' => 60); //Number of Seconds before fail
$db_connect = sqlsrv_connect($db_server, $db_credentials);
//Check the connection to the SQL Database to see if it's valid or else display errors.
if ($db_connect === false) {
die(print_r(sqlsrv_errors(), true));
} else {
echo "Success: Connected to database.";
};
I'm completely stumped, so any help will be useful!
As suggested by #Terminus, installing either the SQL Server driver or SQL Native Client driver on the web server resolves the problem.

Unable to connect PHP to db2 in bluemix

I am very much new to PHP programming and bluemix as well. I was looking for connecting to PHP to bluemix. For that I created SQL DB (DB2 database) in Bluemix and bind it to my app also. Then got the credentials and used it in php using db2_connect(). It didnt work and returned connection failed.
After that I got this:
$vcap_services = json_decode($_ENV["VCAP_SERVICES" ]); $db = $vcap_services->{'mysql-5.5'}[0]->credentials; $mysql_database = $db->name; $mysql_port=$db->port; //$mysql_server_name ='${db->host}:${db->port}'; $mysql_server_name =$db->host . ':' . $db->port; $mysql_username = $db->username; $mysql_password = $db->password;
$con = mysql_connect($mysql_server_name, $mysql_username, $mysql_password);
My question is, should I replace mysql with db2? Or it'll run like this just changing mysql-5.5 to sqldb?
I used db2_connect also and it is not working.
For connecting to the SQLDB service in Bluemix you must use db2_connect rather than mysql_connect, the docs are here. As this is a remote database then you must use a connection string rather than separate databaseName, userName parameters.
Here is an example of how to parse the VCAP_SERVICES and connect to the SQLDB service in PHP:
# Decode JSON and gather DB Info
$services_json = json_decode($json,true);
$sqldb = $services_json["sqldb"];
if (empty($sqldb)) {
echo "No sqldb service instance is bound. Please bind a sqldb service instance";
return;
}
$sqldb_config = $services_json["sqldb"][0]["credentials"];
// create DB connect string
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=".
$sqldb_config["db"].
";HOSTNAME=".
$sqldb_config["host"].
";PORT=".
$sqldb_config["port"].
";PROTOCOL=TCPIP;UID=".
$sqldb_config["username"].
";PWD=".
$sqldb_config["password"].
";";
// connect to database
$conn = db2_connect($conn_string, '', '');
You should not use $mysql_connect, this is MySQL-specific. Use $db2_connect, see the docs for references.
In addition, you are most likely using the wrong credentials (or: an empty object instead). Check the service name from your Bluemix console (expand the service credentials under the service instance in your app screen): most likely they are not "mysql-5.5". I recommend you just print $vcap_services to a console or as debug output in your HTML, and see how it looks like to get the right server/port/user/password.

Connecting PHP to Cloud MYSQL Google Apps

I am trying to connect my google app to a google cloud SQL instance, I have followed all the documentation and have read every page here I can find but no luck so far.
I am connecting using this -
<?php
$host = ":/cloudsql/<your-project-id>:<your-instance-name>";
$user = "root";
$password = " ";
$datbase = "cloudbooks";
mysql_connect($host,$user,$password);
mysql_select_db($datbase);
?>
The error I am getting is
Unable to find the socket transport "unix" - did you forget to enable it when you configured PHP?
Any help would be amazing!
First thing's last.. Do not use mysql_ instead use mysqli_ for all the reasons on this you can check this : Stackoverflow mysql_
Moving on from that, there is no reason you should think of connecting to a MySQL server any different just because of how its hosted. Cloud is a wonderfull Buzz word.. But its nothing new, its still just a host.
So you can use the following in your connection construction.
$host = "hostname // IP";
$user = "username";
$password = "password";
$datbase = "your_database";
There is actually some documentation also on this : google 'cloud' MySQL

FileMaker PHP API Connection Issue

I have recently created a script which should be passed an IP address of the users FM DB Server location, then the script will connect to that server with the given username, password, IP Address and DB Name.
However, no matter what I pass as the IP, it never throws an error.
Is there some form of error handling within the FileMaker PHP API for connection errors?
Thanks in advance!
All the FileMaker API calls return an result object in case of error. You should try this:
Here is an example:
$fm = new FileMaker();
// Set 'hostspec' property using setProperty()
$fm->setProperty('database', $fmConfig['db']);
$fm->setProperty('hostspec', $fmConfig['host']);
$fm->setProperty('username', $fmConfig['user']);
$fm->setProperty('password', $fmConfig['pass']);
$dt = date('m/d/Y H:i:s', $myDate);
$freq = $fm->newFindCommand("myTestLayout_1.0") ;
$freq->addFindCriterion("ModificationTimeStamp", ">".$dt);
$result = $freq->execute();
if (FileMaker::isError($result)) {
$ErrMsg = 'Error code: '.$result->getCode().' Message: '.$result->getMessage();
throw new Exception ($ErrMsg);
}
$foundRecords = $result->getRecords();
echo count($foundRecords)." records";
The server that you're making the calls from needs to have curl support - make sure that's enabled. Best bet is to try locally against your FMS box with the test database - once you've got that working then you can try the remote connection.

Categories