Breaking News

php – how to connect to cloud sql of another project in gcp


echo "IdFirstnameLastname";

class TableRows extends RecursiveIteratorIterator {
    function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);

    function current() {
        return "" . parent::current(). "";

    function beginChildren() {
        echo "";

    function endChildren() {
        echo "" . "n";

//$client = new Google_Client();
//$client->setLoginHint('[email protected]');

$servername = "";
$username = $_POST["username"];
$password = $_POST["password"];
//$mydb = "xp_database";
//$port="3308"; inner-period-262304:asia-east2:xpserve-sqlinstance
//CLOUDSQL_DSN: "mysql:dbname=DATABASE;unix_socket=/cloudsql/inner-period-262304:asia-east2:xpserve-sqlinstance"
$dsn = 'mysql:dbname=xp_database;unix_socket=/cloudsql/inner-period-262304:asia-east2:xpserve-sqlinstance';

$options = array(

    // Coonection establishment
    $conn = new PDO($dsn, $username, $password, $options);
    //$conn = new PDO($dsn, $username);
    //echo $conn;
    // set the PDO error mode to exception
    echo "Connected successfully";

        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $conn->prepare("SELECT custname FROM cust_master_table");

        // set the resulting array to associative
        $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
        foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
            echo $v;

    echo "";

catch(PDOException $e)
    echo "Connection failed: " . $e->getMessage();
echo "hello db9";

I have created a sql instance in one project. My app is in another project in gcp. The app is a php app. Iam not able to retrieve the records from the website. I get the following message in logs

nginx: [warn] the “user” directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3

Please tell me how to go about this.

How to&Answers:

About rankhawks

Check Also

Ionic 4 – Build iOS, Android & Web Apps with Ionic & Angular

Description THIS COURSE WAS COMPLETE UPDATED TO IONIC 4 It’s now up-to-date with the latest version of Ionic! — Ionic is one …

Build Web Apps with Vue JS 2 & Firebase

Build Web Apps with Vue JS 2 & Firebase – Download Udemy Courses For Free …

IOS 12: Learn To Code & Build Real IOS 12 Apps In Swift 4.2

Must have a computer running macOS High Sierra or Mojave (for some sections) Should have …

Website Automation Testing For Beginners With Protractor

Website Automation Testing For Beginners With Protractor Learn how to automate all the repetitive website …

Angular JS Complete Course

Angular JS Complete Course Learn to build robust Applications with the popular AngularJS framework What …

Leave a Reply

Your email address will not be published. Required fields are marked *