本文整理匯總了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;
}