Hello friends.

I have 5 php files having bunch of Inline Queries. I am trying to pluck all the queries from those files and put them in the seperate php file.

When I tried to do so, the variables called in the queries are only defined in those files. So its giving me the error of unknown variables.

Can anyone suggest me the solution?

3 Years
Discussion Span
Last Post by cereal

If you use prepared statements then it's not a problem, create the list of queries:


    return array(

        "query_cities"  => "SELECT * FROM cities WHERE name = ?",
        "query_address" => "SELECT * FROM addresses a JOIN cities c ON c.id = a.city_id WHERE street_name = ? AND zipcode = ?",


Then require the list:


    $list = require './queries.php';

    # query cities
    $param = array(

    $stmt = $pdo->prepare($list['query_city']);
    $city = $stmt->fetchAll();

    # query addresses
    $param = array(

    $stmt = $pdo->prepare($list['query_address']);
    $address = $stmt->fetchAll();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.