How do I connect to a Google Cloud SQL database using CodeIgniter?

前端 未结 2 1546
离开以前
离开以前 2021-01-07 13:39

My CodeIgniter app on Google App Engine is not able to connect to my database on Google Cloud SQL. I tried so many things.

  1. My site loads when I leave database
2条回答
  •  情歌与酒
    2021-01-07 14:09

    Have you authorized your appengine app for access to the Cloud SQL instance? Go to the access control panel on the console for the instance (at https://cloud.google.com/console#/project/{project name}/sql/instances/{instance name}/access-control). Look for authorized app engine applications.

    Otherwise, if you're connecting to the instance successfully, you'll have to choose the database from your code or configuration (depending on the app). For example, from the "running wordpress" guide (https://developers.google.com/appengine/articles/wordpress) you have to define DB_NAME. If you're handling the connections in your own code you'll need to use mysql_select_db.

    From skimming the codeigniter docs, it looks like you need something like: $config['database'] = "mydatabase";

    I'm not familiar with this framework though, so check the docs yourself (http://ellislab.com/codeigniter/user-guide/database/configuration.html).

提交回复
热议问题