AMFPHP复杂sql内部服务器错误gateway.php

时间:2011-11-17 21:48:51

标签: mysql amfphp

好的,我是AMFPHP的新手。我可以毫无问题地做简单的sql语句。

以下是我的学校和地点课程:

class Schools {

public $id;
public $district_id;
public $school_name;

// explicit actionscript class
var $_explicitType = "components.Schools";
}

class Locations {

public $id;
public $school_id;
public $school_address;
public $icon_id;

// explicit actionscript class
var $_explicitType = "components.Locations";
}

这个简单的sql语句没有问题:

    /**
* Retrieves schools data
* @returns id, district_id, school_name
*/

public function getSchools() {
    //connect to the database.
    $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
    mysql_select_db(DATABASE_NAME);
    //retrieve all rows
    $query = "SELECT * FROM schools ORDER BY school_name";
    $result = mysql_query($query);

    $ret = array();
    while ($row = mysql_fetch_object($result)) {
        $tmp = new Schools();
        $tmp->id = $row->id;
        $tmp->district_id = $row->district_id;
        $tmp->school_name = $row->school_name;
        $ret[] = $tmp;
    }
    mysql_free_result($result);
    return $ret;
}

但是,我很难让“有点”复杂的sql语句正常工作。

    /**
* Retrieves schools with locations data
* @returns school_name, school_address
*/

public function getSchoolsLocations() {
    //connect to the database.
    $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
    mysql_select_db(DATABASE_NAME);
    //retrieve all schools with their locations
    $query = "SELECT schools.school_name AS SNAME, school_address AS SLOC FROM schools, locations WHERE schools.id = locations.school_id";
    $result = mysql_query($query);

    $ret = array();
    while ($row = mysql_fetch_object($result)) {
        $tmp = new Schools();
        $tmp->id = $row->id;
        $tmp->school_name = $row->SNAME;
        $ret[] = $tmp;

        $tmp2 = new Locations();
        $tmp2->school_id = $row->school_id;
        $tmp2->school_address = $row->SLOC;
        $ret2[] = $tmp2;

        array_splice($ret, count($ret), 0, $ret2);
    }
    mysql_free_result($result);
    return $ret;
}

BTW,SELECT schools.school_name AS SNAME, school_address AS SLOC FROM schools, locations WHERE schools.id = locations.school_id在mysql中完美运行。

1 个答案:

答案 0 :(得分:0)

看起来你没有宣布$ ret2。

FWIW:如果将其格式化为连接,您的查询可能会获得更好的性能。只是一个想法。