当前位置: 首页>>代码示例>>PHP>>正文


PHP SqlParser::ParseString方法代码示例

本文整理汇总了PHP中SqlParser::ParseString方法的典型用法代码示例。如果您正苦于以下问题:PHP SqlParser::ParseString方法的具体用法?PHP SqlParser::ParseString怎么用?PHP SqlParser::ParseString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SqlParser的用法示例。


在下文中一共展示了SqlParser::ParseString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: transaction

function transaction($sql)
{
    global $response, $apiKey, $data, $basePath;
    $parsedSQL = SqlParser::ParseString($sql)->getArray();
    //$tokens = SqlParser::Tokenize($sql, true);
    if (strpos($sql, ';') !== false) {
        $response['success'] = false;
        $response['message'] = "You can't use ';'. Use the bulk transaction API instead";
    } elseif (strpos($sql, '--') !== false) {
        $response['success'] = false;
        $response['message'] = "SQL comments '--' are not allowed";
    } elseif ($parsedSQL['drop']) {
        $response['success'] = false;
        $response['message'] = "DROP is not allowed through the API";
    } elseif ($parsedSQL['alter']) {
        $response['success'] = false;
        $response['message'] = "ALTER is not allowed through the API";
    } elseif ($parsedSQL['create']) {
        $response['success'] = false;
        $response['message'] = "CREATE is not allowed through the API";
    } elseif ($parsedSQL['update'] || $parsedSQL['insert'] || $parsedSQL['delete']) {
        if ($apiKey == $_REQUEST['key'] || $apiKey == false) {
            $api = new sqlapi();
            $response = $api->transaction($_REQUEST['q']);
        } else {
            $response['success'] = false;
            $response['message'] = "Not the right key!";
        }
    } elseif ($parsedSQL['select']) {
        parse_str(urldecode($_SERVER['QUERY_STRING']), $args);
        $id = $args['q'];
        if (!$args['lifetime']) {
            $args['lifetime'] = 0;
        }
        $options = array('cacheDir' => "{$basePath}/tmp/", 'lifeTime' => $args['lifetime']);
        $Cache_Lite = new Cache_Lite($options);
        if ($data = $Cache_Lite->get($id)) {
            //echo "cached";
        } else {
            ob_start();
            if ($_REQUEST['srs']) {
                $srs = $_REQUEST['srs'];
            } else {
                $srs = "900913";
            }
            $api = new sqlapi($srs);
            $api->execQuery("set client_encoding='UTF8'", "PDO");
            $response = $api->sql($_REQUEST['q']);
            echo json_encode($response);
            // Cache script
            $data = ob_get_contents();
            $Cache_Lite->save($data, $id);
            ob_get_clean();
        }
    } else {
        $response['success'] = false;
        $response['message'] = "Check your SQL. Could not recognise it as either SELECT, INSERT, UPDATE or DELETE";
    }
    return $response;
}
开发者ID:valentijnvenus,项目名称:geocloud,代码行数:60,代码来源:sql_c.php


注:本文中的SqlParser::ParseString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。