DomSQLv3
makes web smaller
Support This Project

Download DomSQL

Example query: ( code is editable )    [>>Run<<]    ( This is a test page! Only "variable://" pseudo protocall is supported! )



Example page: ( code is editable ). Or paste code ( from external webpage ) here!



PHP way to use DomSQLv3
/* As simple as that */
 include('domsql.php');
$a = (new domsql())->q('select a.{//title[1]=>value} as title FROM {http://example.com} as a');
/* PDO::fetchAll as a result */
Some more examples:
/*
!NOTE
!NOTE
!NOTE all the examples can be combined in one query. 
Default database driver is sqlite ( mysql and pgsql are also available ).
SQL syntax ( joins, Aggregate Functions  etc. ) is available and depends on driver that is used 
(can be configured in domsqlCore::defaultRootDrv )
!NOTE Current example uses syntax compatable with php 5.5.9
For lower versions, up to 5.5.3 you can use

$r = new domsql(); 
echo $r->q($query);

instead of:

echo (new domsql())->q($query);

Not tested on lower than 5.5.3 versions !
Happy coding ;) 
*/

/* Login and save session ( using CURL setopt )*/
$a = (new domsql())->q('select a.{//title[1]=>value} from {http://example.com=>opt("CURLOPT_POST":"1","CURLOPT_POSTFIELDS":"user=uname&pass=password","CURLOPT_COOKIEFILE":"cookiefile.txt","CURLOPT_COOKIEJAR":"cookiefile.txt")} as a ');
print_r($a);

/* imap email checking: class domsqlHandleImap */
$a = (new domsql())->q('select a.{//msg[1]=>elementCode} from {imap://mymail%40gmail.com:mypass@imap.gmail.com:993/imap/ssl/novalidate-cert#INBOX} as a ');
print_r($a);

/* parse string : domsqlHandleString */
$a = (new domsql())->q('select a.{//title[1]} from {string://<html><title>title text</title><body>bodytext</body></html>} as a ');
print_r($a);

/* file parsing: class domsqlHandleFile */
$a = (new domsql())->q('select a.{//title[1]=>elementCode} from {file://localFilePath.xml} as a ');
print_r($a);

/* variable parsing: class domsqlHandleVriable */
$examplePage="<html><title>example title</title><body>example body</body></html>"; // should be in the global ( root ) scope
$a = (new domsql())->q('select a.{//title[1]=>elementCode} from {variable://examplePage} as a ');
print_r($a);

/* get property of element: class  domsqlModifierProperty */
$a = (new domsql())->q('select a.{//body[1]=>property(class)} from {string://<html><title>title text</title><body class="className">bodytext</body></html>} as a ');
print_r($a);

/* get value of element: class  domsqlModifierValue */
$a = (new domsql())->q('select a.{//body[1]=>value} from {string://<html><title>title text</title><body class="className">bodytext</body></html>} as a ');
print_r($a);

/* get innerCode of element: class domsqlModifierInnerCode  */
$a = (new domsql())->q('select a.{//body[1]=>innerCode} from {string://<html><title>title text</title><body class="className"><span>bodytext</span></body></html>} as a ');
print_r($a);

/* get elementCode of element: class domsqlModifierElementCode */
$a = (new domsql())->q('select a.{//body[1]=>elementCode} from {string://<html><title>title text</title><body class="className"><span>bodytext</span></body></html>} as a ');
print_r($a);

/* command line usage:
put this line in your php file.*/
echo (new domsqlInterfaceCli())->pull();
/* Terminal:*/
#bash$ php5 dsql3.php -o print_r -q 'select {//title[1]=>value} from {http://example.com}'