PHP code example of crodas / sql-parser
1. Go to this page and download the library: Download crodas/sql-parser library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crodas / sql-parser example snippets
$parser = new SQLParser;
$queries = $parser->parse("SELECT * FROM table1 WHERE id = :id");
var_dump(get_class($queries[0])); // string(16) "SQLParser\Select"
var_dump($queries[0]->getTable()[0]->getValue()); // string(6) "table1"
/*
array(1) {
[0] =>
string(2) "id"
}
*/
var_dump($queries[0]->getVariables());
// SELECT * FROM 'table1' WHERE 'id' = :id
echo $queries[0] . "\n";
SQLParser\Writer\SQL::setInstance(new SQLParser\Writer\MySQL);
// SELECT * FROM `table1` WHERE `id` = :id
echo $queries[0] . "\n";