Connecting PHP to Cloud MYSQL Google Apps - php

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

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.

PHP GMail IMAP Connection Failure

I am using this repo for connecting to the gmail. But its getting error. I hope someone has experience handling this recently.
<?php
namespace program;
require_once "php-imap-client/vendor/autoload.php";
use SSilence\ImapClient\ImapClientException;
use SSilence\ImapClient\ImapConnect;
use SSilence\ImapClient\ImapClient as Imap;
$mailbox = 'imap.gmail.com';
$username = 'alice#gmail.com';
$password = "wonderland";
$encryption = Imap::ENCRYPT_SSL;
// Open connection
try{
$imap = new Imap($mailbox, $username, $password, $encryption);
// You can also check out example-connect.php for more connection options
}catch (ImapClientException $error){
echo $error->getMessage().PHP_EOL;
die(); // Oh no :( we failed
}
I've had this before too. From the link in the error message you're receiving.
Allow less secure apps: If you don't use 2-Step Verification, you
might need to allow less secure apps to access your account.
Here's a guide to do so

Connecting to Oracle Database 11g using PHP code

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

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.

PHP PDO OCI TNS adatpter error (c:635)

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']
);

Categories