Welcome Guest, Not a member yet? Register   Sign In
Google Cloud SQL connection
#1

(This post was last modified: 12-22-2015, 07:22 AM by mr_pablo.)

I have just moved form CI2 to CI3 and I am having trouble getting a DB connection to my Google Cloud SQL DB.

In CI2, I used:

PHP Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'my_db';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['socket'] = '/cloudsql/my-google-project-name:my-db-name'

And I had to modify the MySQLi Driver:

PHP Code:
function db_connect()
 {
 
           if(isset($this->socket)){

 
               return mysqli_connect(null$this->usernamenull$this->databasenull$this->socket);

 
           }
 
           elseif ($this->port != '')
 
           {
 
               return @mysqli_connect($this->hostname$this->username$this->password$this->database$this->port);
 
           }
 
           else
            
{
 
                   return @mysqli_connect($this->hostname$this->username$this->password$this->database);
 
           }

 } 

But now in CI3, the DB config does not work.

I changed the hostname to be what the socket is set to, but it doesn't seem to have helped.

Any ideas?


EDIT - Never mind, I was being stupid. I hadn't set my development environment session variables properly.
Reply


Messages In This Thread
Google Cloud SQL connection - by mr_pablo - 12-22-2015, 06:32 AM
RE: Google Cloud SQL connection - by nilanjanr0y - 07-19-2018, 08:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB