本文整理汇总了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;
}