发送REST调用Google云PHPMyAdmin服务器不工作?

通过以下链接,我已经在Google Cloud上成功部署了一个phpMyAdmin服务器。 我无法写入到我在phpMyAdmin中创build的数据库中。 我正在尝试基于Google发布的新Firebase Cloud Messaging创build通知服务。

NotificationInstanceService.java

 public class NotificationInstanceService extends FirebaseInstanceIdService { private static final String TAG = "NotificationInstance"; @Override public void onTokenRefresh() { //Getting registration token String refreshedToken = FirebaseInstanceId.getInstance().getToken(); //Displaying token on logcat Log.d(TAG, "Refreshed token: " + refreshedToken); sendRegistrationToServer(refreshedToken); } private void sendRegistrationToServer(String token) { //You can implement this method to store the token on your server //Not required for current project OkHttpClient client = new OkHttpClient(); //Create the request body RequestBody body = new FormBody.Builder().add("Token", token).build(); //Know where to send the request to Request request = new Request.Builder().url("<db link>.appspot.com/fcm/register.php") .post(body) .build(); //Create try { client.newCall(request).execute(); } catch (IOException e) { e.printStackTrace(); } } } 

我在https://<db link>.appspot.com上部署了/fcm/register.php文件,它看起来像这样:

register.php

 <?php if (isset($_POST["Token"])) { $_uv_Token=$_POST["Token"]; $conn = mysqli_connect("<db link>.appspot.com","root","","fcm") or die("Error connecting"); $q="INSERT INTO users (Token) VALUES ( '$_uv_Token') " ." ON DUPLICATE KEY UPDATE Token = '$_uv_Token';"; mysqli_query($conn,$q) or die(mysqli_error($conn)); mysqli_close($conn); } ?> 

我很困惑,因为我似乎没有写任何东西给我的数据库称为用户,我知道我已经在phpMyAdmin创build的MySQL服务器中创build。 我知道用户名和密码也已经设置register.php. 有没有什么办法可以debugging我的脚本是否真的进入PHP代码? 我如何debuggingPHP代码? 我也认为这个请求实际上正在构build,因为我可以通过这部分代码进行debugging。 任何帮助,将不胜感激。 谢谢!

编辑:我试图部署我的服务器时可能会有所帮助的一些文件:

app.yaml中:

 application: <app server url> service: default runtime: php55 api_version: 1 version: alpha-001 handlers: - url: /(.+\.(ico|jpg|png|gif))$ static_files: \1 upload: (.+\.(ico|jpg|png|gif))$ application_readable: true - url: /(.+\.(htm|html|css|js))$ static_files: \1 upload: (.+\.(htm|html|css|js))$ application_readable: true - url: /(.+\.php)$ script: \1 login: admin - url: /.* script: index.php login: admin - url: /.* script: register.php login: admin 

config.inc.php文件:

 <?php $cfg['blowfish_secret'] = '<Secret>'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */ /* * Servers configuration */ $i = 0; // Change this to use the project and instance that you've created. $host = '/cloudsql/<app server url>:us-central1:<database name>-app-php'; $type = 'socket'; /* * First server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['socket'] = $host; $cfg['Servers'][$i]['connect_type'] = $type; $cfg['Servers'][$i]['compress'] = false; /* Select mysql if your server does not have mysqli */ $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['AllowNoPassword'] = true; /* * End of servers configuration */ /* * Directories for saving/loading files from server */ $cfg['UploadDir'] = ''; $cfg['SaveDir'] = ''; $cfg['PmaNoRelation_DisableWarning'] = true; $cfg['ExecTimeLimit'] = 60; $cfg['CheckConfigurationPermissions'] = false; // [END all] 

php.ini中:

 google_app_engine.enable_functions = "php_uname, getmypid" 

编辑:在浏览器中的文本,去.appspot.com / fcm / register.php

array(11){[“pmaCookieVer”] => string(1)“5”[“pma_lang”] => string(2)“en”[“pma_collat​​ion_connection”] => string(15)“utf8_unicode_ci”[“pma_console_height “] =>串(2) ”92“[” SACSID “] =>的string(355) ”〜AJKiYcFgym76QZfbMX35ddCTdKKf-O7q5koLvNZ0coWTMvw9aNlR5fusNyLRzFyw5DB_t2ygVuTEjHwgrgBco4-wr_V3Eer_Mf0CDuGX2e4IpirCNeiGxkRvaLgRPPyZNZWKUx1mF_DChjsksTirkY5WCzlA3G3MO9bBScrLw8kNOFGnvzkev3-B2x31s_TmnDN5aJ0G3-nPueI4FPpKaaMlPsITziccvXMpiehglQOKoo1Bol3EZSF1tjI9QoJuc-6X_sHgJ0IEppg7K-cBapaEx5CmDD2kWOggnVPWnGj1SiKFUnE3DZD46bjovf5me7IdwfVX22bv5D2PJDPQEN4m3D7yP3-WDG“[” pma_console_config“] =>串(103 )“{”alwaysExpand“:false,”startHistory“:false,”currentQuery“:true,”enterExecutes“:false,”darkTheme“:false}”[“pma_console_mode”] => string(4) phpMyAdmin“] => string(40)”cfd814e10982d138c7ed4a3ef510c454c0e5f9b9“[”pma_iv-1“] => string(24)”bSPnJOOBe5x0iXPbbU5Nww ==“[”pmaUser-1“] => string(24)”oHSLKZ7q6eOaXJ475Q6tzw ==“[” pmaPass-1“] => string(24)”dwKZ9gQPCoe / Uk4sWS4s2g ==“}

新的register.php:

 <?php if (isset($_REQUEST["Token"])) { $_uv_Token=$_REQUEST["Token"]; $conn = mysqli_connect("/cloudsql/<Database ServerURL>","root","","FCM") or die("Error connecting"); $q="INSERT INTO users (Token) VALUES ( '$_uv_Token') " ." ON DUPLICATE KEY UPDATE Token = '$_uv_Token';"; var_dump(mysqli_query($conn,$q)); mysqli_query($conn,$q) or die(mysqli_error($conn)); mysqli_close($conn); } else { var_dump($_REQUEST); } ?> 

NotificationInstanceService.java

新的POST请求:

  Request request = new Request.Builder().url("<Application Server>/fcm/register.php?Token=123") .post(body) .build(); 

Solutions Collecting From Web of "发送REST调用Google云PHPMyAdmin服务器不工作?"

我不知道你的问题到底是什么,现在还不清楚。 但既然你问: Is there any way I can debug whether or not my script is actually going into the PHP code? How can I debug the PHP code? Is there any way I can debug whether or not my script is actually going into the PHP code? How can I debug the PHP code? 这里是你的答案:

把你的php代码改成这样:

 <?php if (isset($_POST["Token"])) { $_uv_Token=$_POST["Token"]; $conn = mysqli_connect("<db link>.appspot.com","root","","fcm") or die("Error connecting"); $q="INSERT INTO users (`Token`) VALUES ( `{$_uv_Token}`) " ." ON DUPLICATE KEY UPDATE `Token` = `{$_uv_Token}`;"; mysqli_query($conn,$q) or die(mysqli_error($conn)); mysqli_close($conn); } else { echo "Token is not set!"; } ?> 

然后在NotificationInstanceService.java检查OkHttpClient调用的响应:

 ... try { Response response = client.newCall(request).execute(); } catch (IOException e) { e.printStackTrace(); } if (!response.isSuccessful()){ Log.w(TAG, "Unexpected response"+response.toString()); } else { Log.w(TAG, "response: "+response.body().string()); } ...