Monday, October 6, 2014

Loading external sql files in PHP




I have a large sql file. I preferred  to separate it from PHP code.
I created a SQL directory to put these sql files. Using PHP function file_get_contents to laod
external sql files.
    $db2 = new ConnectionDB2();
    $sql = file_get_contents(SITE_SERVER_ROOT."/_models/SQL/CSRPTcourses_lut.sql");
    $result = $db2->query($sql);
    $data = array();
    while ($row = $db2->getArray($result)) {
            $data[] = $row;
        }

     $db2->close();

No comments:

Post a Comment