将变量传递给静态函数

Passing variable to static function

我有一些 PHP 可以提取数据库中的所有员工记录。

我现在想加一个子句,这样就可以了SELECT * WHERE companyId = x

我正在使用 GET 检索要使用的 companyId

我的问题是,如何将 $companyClause 传递给静态函数?

function viewStaffInCompany(){

    $results = array();
    $companyClause = $_GET["companyClause"];
    echo $companyClause . "<br><hr>";

    $data = Staff::getCompanyStaffList();
    $results['staff'] = $data['results'];
    $results['totalRows'] = $data['totalRows'];

    require( "templates/viewStaff.php" );

};

getCompanyStaffList();

public static function getCompanyStaffList( $numRows=1000000, $order="id ASC", $companyClause) {
    $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );

    $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM Staff WHERE $companyClause ORDER BY " . $order . " LIMIT :numRows";

    $st = $conn->prepare( $sql );
    $st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
    $st->execute();
    $list = array();

    while ( $row = $st->fetch() ) {
      $users = new Staff( $row );
      $list[] = $users;
    }

    // Now get the total number of staff that matched the criteria
    $sql = "SELECT FOUND_ROWS() AS totalRows";
    $totalRows = $conn->query( $sql )->fetch();
    $conn = null;
    return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
  }

作为参数。

Staff::getCompanyStaffList(1000000, "id ASC", $companyClause);

但我会重构这个参数列表,因为 $companyClause 是必需的,所以,您将需要始终传递前 2 个参数,如果没有给出,则有默认值。

所以应该是:

public static function getCompanyStaffList($companyClause, $numRows=1000000, $order="id ASC") {