带有多个文件夹的Google App Engine PHP

时间:2014-06-19 02:56:41

标签: php google-app-engine app.yaml

我无法在不同的文件夹中运行脚本。 Google App Engine的新功能,对YAML来说是全新的。

文件夹结构为:

/login.php
/includes/mySQLConnection.php

的app.yaml

application: test
version: 1
runtime: php
api_version: 1

handlers:
- url: /includes
  static_dir: includes
  application_readable: true
- url: /login.php
  script: login.php

的login.php

<?php
    header('Content-type: application/json');

    if($_POST) {
    //Get Username and Password
    $user_email = strip_tags(trim(strtolower($_POST['username'])));
    $user_password = strip_tags(trim($_POST['password']));

    //Connect to mySQL Server
    include $_SERVER['DOCUMENT_ROOT']."includes/mySQL_connection.php";

    // //Select which database to work with
    $database = mysql_select_db("test",$mySQL_connection) or die("Cannot connect to user table");

            echo json_encode(array('success' => 1,'error_message' => "Success"));
    }
?>

/includes/mySQL_connection.php

<?php
    $hostname = '127.0.0.1:3306'; 
    $db_username = 'root';
    $db_password = '';

    //connection to the database
    $mySQL_connection = mysql_connect($hostname, $db_username, $db_password) or die("Unable to connect to MySQL");
?>

这不起作用,但如果我从/includes/mySQL_connection.php中取出所有代码并将其放入/login.php,那么它可以完美地运行。

有人能指出我正确的方向吗?

1 个答案:

答案 0 :(得分:1)

DOCUMENT_ROOT没有尾随'/',看起来你需要添加一个。

http://php-minishell.appspot.com/我尝试了

>>> echo $_SERVER['DOCUMENT_ROOT'];
/base/data/home/apps/s~php-minishell/20140319.374522287571266149

所以可能会将您的代码更改为

   //Connect to mySQL Server
    include $_SERVER['DOCUMENT_ROOT']."/includes/mySQL_connection.php";