Connecting to Oracle Database 11g using PHP code - php

I am trying to develop a web application with php that will connect to an 11g oracle database.
Here is my code:
//database parameter
$db_name = "my_base";
$user = "username";
$password = "password";
$sid = "sid_number";
$port = "1521";
//function of connection
$conn = oci_connect ($user, $password, "//localhost/".$db_name);
Is the connection line correct? Also I'm not introducing the port number and sid. Can someone tell me if the port number and sid are required or not?

Your connection string is correct it's not required port number & service number but if aren't able to connect & you changed the default setting you can always add port number & service in your connection string like this [//]host_name[:port][/service_name][:server_type][/instance_name] read more from here http://php.net/manual/en/function.oci-connect.php#refsect1-function.oci-connect-parameters

Related

Integration odoo 9.0 with PHP

867/5000
Hello everyone!
I have a problem, in the place where I work they want me to create a login screen for the CRM so that the client, just enter their e-mail and password, and go directly to their CRM (without having to choose between all the databases ). The question is that you create a database and a login with php, clients at the beginning of the session ask all the data to the database so that it is directly connected with odoo.
When I bring all the data, I will put them in the corresponding field so that I send them to odoo (Work with odoo 9.0 and Ripcord). How can I establish that connection with odoo and that when it is successful, it redirects me to the client's CRM and leaves the login screen that believes it is hosted on a server?
I hope to have explained myself well, anything explained back. Thanks for your help in advance.
Regards!
Here is my code:
<?php
require_once('ripcord-master/ripcord.php');
$url = $ODOO_URL; //ODOO Server Url
$db = $user['codigo']; //Database Name
$username = $user['usuario']; //UserName
$password = $user['password_odoo']; //Password
$common = ripcord::client("$url/xmlrpc/2/common");
//Authenticate the credentials
$uid = $common->authenticate($db, $username, $password, array());
//Create Model Instance
$models = ripcord::client("$url/xmlrpc/2/object");
// Fetch the data by calling appropriate methods
$partner_field = array();
$partner_field=$models->execute_kw($db, $uid, $password,
'res.partner', 'fields_get',array(),
array('attributes' => array('string', 'help',
'type')));
?>
What I try to do is that when I verify that the user's data is correct, I redirect to the odoo page with the customer's CRM open.

AD on Windows Server 2012 + Windows LDAP + PHP Bind

I've set up Active Directory and ADLDAP on Windows server 2012. I'm trying a simple ldap_bind but continue to have a "invalid credentials" error spit back to me.
In my AD Users and Groups screen, I clearly see the domain I made along with the OU (organizational unit) and users inside of it. ASDI Edit clearly tells me the DN for that user:
CN=Bob Smith,OU=Accounting,DC=mydomain,DC=net
Further, the BaseDN is clearly told to me in ASDI Edit because it's above the OU group "accounting" -
DC=mydomain,DC=net
Now onto my script - which throws no LDAP connect errors, only on bind, with a constant invalid credentials:
$connectionLDAP = "LDAP://localhost:54126";
$basedn = 'DC=mydomain,DC=net';
$ldap = ldap_connect($connectionLDAP) or die("Could not connect to LDAP server.");
$username = $post['username'];
$password = $post['password'];
$usernameForBind = "CN=".$username.",OU=Accounting,".$basedn;
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = ldap_bind($ldap, $usernameForBind, $password);
This spits the following warning, and of course my script ends there since there is no positive match to username and password found:
Warning: ldap_bind(): Unable to bind to server: Invalid credentials in C:\....\login.php on line 41
And the below error echos produce this:
echo(ldap_error($ldap)."<br>");
echo(ldap_errno($ldap)."<br>");
Invalid credentials
49
I have tried every combination of DN, username, email address, mydomain\username without the rest of the DN info, everything I can think of....but for the life of me it won't take, and google + Stack searches unfortunately aren't helping me at the moment get past this.
Thanks for any assistance.
You are using Active directory on Windows, So please change your code to following It would work. Because AD need #domain_name as username suffix in bind function.
$connectionLDAP = "ldap://localhost";
$basedn = '#mydomain.net';
$ldap = #ldap_connect($connectionLDAP, 54126) or die("Could not connect to LDAP server.");
$username = $post['username'];
$password = $post['password'];
$usernameForBind = $username.$basedn;
#ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
#ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = #ldap_bind($ldap, $usernameForBind, $password);
I've tested such scenarios many times, It works for AD.
And also Please make sure that your AD server is running on the same port you're using in code ie. 54126.

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

Server can not accept argument. FTP upload in shell

$local = 'WP_Inv.csv';
$remote = 'WP_Inv.csv';
$user = "User861";
$pass = "topsecret";
$host = 'ftp.server.com';
$port = '21';
$timeout = '90';
$type = FTP_ASCII;
$conn_id = ftp_connect($host,$port,$timeout);
$login = ftp_login($conn_id, $user, $pass);
ftp_put($conn_id, $remote, $local, $type);
returning the following error when ran from shell:
The very last line is showing an error, any help would be great I am pulling my hair out!
PHP Warning: ftp_put(): Server cannot accept argument.
(Yes I close my connection later in the code)
Have you tried turning on passive mode? I've had the same issue in the past and its because the machine running the php code and the ftp server could not handshake on an active connection.
http://php.net/manual/en/function.ftp-pasv.php
bool ftp_pasv ( resource $ftp_stream , bool $pasv )
ftp_pasv() turns on or off passive mode. In passive mode, data connections are initiated by the client, rather than by the server. It may be needed if the client is behind firewall.
Please note that ftp_pasv() can only be called after a successfull login or otherwise it will fail.

Categories