{"id":950,"date":"2014-04-20T15:13:21","date_gmt":"2014-04-20T15:13:21","guid":{"rendered":"http:\/\/tw.newtonstudio.com\/?p=950"},"modified":"2014-05-27T02:10:14","modified_gmt":"2014-05-27T02:10:14","slug":"%e5%9c%a8-google-appengine-%e4%b8%8a%e4%bd%bf%e7%94%a8codeignitor-%e9%96%8b%e7%99%bc%e8%aa%9e%e8%a8%80%e8%88%87%e8%b3%87%e6%96%99%e5%ba%ab-phpmysql","status":"publish","type":"post","link":"https:\/\/tw.newtonstudio.com\/?p=950","title":{"rendered":"\u5728 Google AppEngine \u4e0a\u4f7f\u7528Codeignitor, \u958b\u767c\u8a9e\u8a00\u8207\u8cc7\u6599\u5eab PHP+MYSQL"},"content":{"rendered":"<p>Google Cloud Platform \u958b\u59cb\u652f\u63f4PHP\u4e86!<br \/>\n\u96d6\u7136\u9084\u662f\u5728BETA\u968e\u6bb5, \u4f46\u9084\u662f\u8b93\u4eba\u5fcd\u4e0d\u4f4f\u8981\u6e2c\u8a66\u4e00\u4e0b\u5440~<br \/>\n\u9019\u6b21\u7684\u6e2c\u8a66\u662f\u4f7f\u7528CodeIgnitor\u4f86\u4f7f\u7528,<br \/>\n\u7d50\u5408Google Cloud SQL,<br \/>\n\u5728\u672c\u6a5f\u9023\u8cc7\u6599\u5eabMYSQL\u662f\u6c92\u554f\u984c,<br \/>\n\u4f46DEPLOY\u4e4b\u5f8c\u767c\u73fe\u6b63\u5f0f\u6a5f\u4e00\u76f4\u6c92\u8fa6\u6cd5\u9023\u4e0a.<br \/>\n\u932f\u8aa4\u8cc7\u8a0a\u5982\u4e0b:<\/p>\n<pre>\r\nA Database Error Occurred\r\nUnable to connect to your database server using the provided settings.\r\nFilename: core\/Loader.php\r\nLine Number: 346\r\n<\/pre>\n<p><a class=\"thumbnail\" href=\"http:\/\/tw.newtonstudio.com\/wp-content\/uploads\/2014\/04\/cuowu.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/tw.newtonstudio.com\/wp-content\/uploads\/2014\/04\/cuowu.jpg\" alt=\"\" title=\"cuowu\" width=\"520\" height=\"233\" class=\"aligncenter size-full wp-image-953\" srcset=\"https:\/\/tw.newtonstudio.com\/wp-content\/uploads\/2014\/04\/cuowu.jpg 520w, https:\/\/tw.newtonstudio.com\/wp-content\/uploads\/2014\/04\/cuowu-300x134.jpg 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><\/a><\/p>\n<p>\u67e5\u4e86stackoverflow\u4e4b\u5f8c\u624d\u767c\u73fe \/application\/config\/database.php\u7684\u8a2d\u5b9a\u9700\u8981\u5fae\u8abf\u624d\u80fd\u9023\u5230\u8cc7\u6599\u5eab:<\/p>\n<pre>\r\n$db['default']['hostname'] = 'localhost';\r\n$db['default']['username'] = 'root';\r\n$db['default']['password'] = '\u5bc6\u78bc';\r\n$db['default']['database'] = '\u8cc7\u6599\u5eab\u540d\u7a31';\r\n$db['default']['dbdriver'] = 'mysqli';\r\n$db['default']['dbprefix'] = '';\r\n$db['default']['pconnect'] = FALSE;\r\n$db['default']['db_debug'] = FALSE;\r\n$db['default']['cache_on'] = FALSE;\r\n$db['default']['cachedir'] = '';\r\n$db['default']['char_set'] = 'utf8';\r\n$db['default']['dbcollat'] = 'utf8_general_ci';\r\n$db['default']['swap_pre'] = '';\r\n$db['default']['autoinit'] = FALSE;\r\n$db['default']['stricton'] = FALSE;\r\n$db['default']['socket'] = '\/cloudsql\/PROJECT-ID:INSTANCEID';\r\n<\/pre>\n<p>\u6700\u5f8c\u4e00\u884c\u7684SOCKET\u662fcodeignitor\u9810\u8a2d\u6c92\u6709\u7684\u53c3\u6578,<br \/>\n\u8981\u8a18\u5f97\u52a0\u4e0a\u624d\u80fd\u6210\u529f\u9023\u7dda<\/p>\n<p>\u9023\u7dda\u4e4b\u5f8c, \u4f60\u6703\u767c\u73fe\u7db2\u7ad9\u96d6\u7136\u53ef\u4ee5\u555f\u52d5\u4e86,<br \/>\n\u4f46\u90fd\u6c92\u6709\u8cc7\u6599!\u600e\u9ebc\u56de\u4e8b\u5462?<br \/>\n\u539f\u4f86\u662f\u56e0\u70ba\u4ed6\u6703\u4e00\u76f4\u9810\u8a2d\u9023\u5230localhost,<br \/>\n\u9019\u6642\u5fc5\u9808\u8981\u4fee\u6539mysqli\u7684drivers.<\/p>\n<p>\u5230 application\/system\/database\/drivers\/mysqli\/mysqli_driver.php \u5c07 db_connect \u53d6\u4ee3\u6210\u4ee5\u4e0b\u7684\u51fd\u6578:<\/p>\n<pre>\r\nfunction db_connect()\r\n{\r\n    if(isset($this->socket)){\r\n        return mysqli_connect(null, $this->username, null, $this->database, null, $this->socket);\r\n    }\r\n    elseif ($this->port != \u201d)\r\n    {\r\n        return mysqli_connect($this->hostname, $this->username, $this->password, $this->database, $this->port);\r\n    }\r\n    else\r\n    {\r\n        return mysqli_connect($this->hostname, $this->username, $this->password, $this->database);\r\n    }\r\n}\r\n<\/pre>\n<p>\u5c31\u5927\u529f\u544a\u6210\u62c9!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google Cloud Platform \u958b\u59cb\u652f\u63f4PHP\u4e86! \u96d6\u7136\u9084\u662f\u5728BETA\u968e\u6bb5, \u4f46\u9084\u662f\u8b93\u4eba\u5fcd\u4e0d\u4f4f\u8981\u6e2c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[209,210,23,211,70],"class_list":["post-950","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-gae","tag-google-appengine","tag-lamp","tag-mysql","tag-php"],"_links":{"self":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=950"}],"version-history":[{"count":7,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/950\/revisions"}],"predecessor-version":[{"id":956,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/950\/revisions\/956"}],"wp:attachment":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}