All pastes #886121 Raw Edit

Unnamed

public text v1 · immutable
#886121 ·published 2008-01-31 13:32 UTC
rendered paste body
<?php

	include('./myio.php');
	include('./myiodriver.php');
	include('./myioexception.php');
	
    $db = new MyIO(Array('host'=>'localhost', 'user'=>'', 'pass'=>'', 'db'=>''));

    echo <<<EOH
    <br />
    <h2 style="margin: 0px; padding: 0px;">Trial #1:</h2>
    <b>Experiment:</b> Testing where fields with multiple operator types and out of order.<br />
    <b>Code:</b><br />
    <b>Result:</b><br />
    <i>
EOH;

	$test = $db->tblproducts->get()->whereFldtype('test');
	$test->wherejoin('fldtest', 'or');
	$test->whereFldtest('test');
	$test->where('tbltest.fld', 'value');
	$test->wherejoin('tbltest.fld', '&&');
	$test->limit(1,2);
	$test->order('fldtest asc', 'fldtype desc');
	$test->print();
	
    echo '</i>';
	
    $test->varReset();
    
    echo <<<EOH
    <br /><br />
    <h2 style="margin: 0px; padding: 0px;">Trial #2:</h2>
    <b>Experiment:</b> Testing joins and out of order where fields combined.<br />
    <b>Result:</b><br />
    <i>
EOH;

	$test = $db->tblproducts->get()->whereFldtype('test');
	$test->wherejoin('fldtest', 'or');
	$test->whereFldtest('test');
	$test->where('tbltest.fld', 'value');
	$test->wherejoin('tbltest.fld', '&&');
	$test->join('table', 'table.id', 'table1.id');
	$test->joinLeft('table', 'table.id', 'table1.id');
	$test->limit(1,2);
	$test->order('fldtest asc', 'fldtype desc');
	$test->joinRight('table', 'table.id', 'table1.id');
	$test->print();
	
    echo '</i>';
    
    $test->varReset();
    
    echo <<<EOH
    <br /><br />
    <h2 style="margin: 0px; padding: 0px;">Trial #3:</h2>
    <b>Experiment:</b> Testing individual select columns, and multiple where joins all out of order.<br />
    <b>Result:</b><br />
    <i>
EOH;

	$test = $db->tblproducts->whereFldtype('test');
	$test->wherejoin('fldtest', 'or');
	$test->whereFldtest('test');
	$test->where('tbltest.fld', 'value');
	$test->wherejoin('tbltest.fld', '&&');
	$test->limit(1,2);
	$test->order('fldtest asc', 'fldtype desc');
	$test->get('table1.id', 'table2.*', 'table1.tid');
	$test->print();
	
    echo '</i>';
    
    $test->varReset();
    
    echo <<<EOH
    <br /><br />
    <h2 style="margin: 0px; padding: 0px;">Trial #4:</h2>
    <b>Experiment: Supplying insufficient parameters</b> <br />
    <b>Result:</b><br />
    <i>
EOH;

	$test = $db->tblproducts->whereFldtype('test');
	$test->join('table', 'table.id');
	$test->wherejoin('fldtest', 'or');
	$test->whereFldtest('test');
	$test->where('tbltest.fld', 'value');
	$test->wherejoin('tbltest.fld', '&&');
	$test->limit(1,2);
	$test->order('fldtest asc', 'fldtype desc');
	$test->get('table1.id', 'table2.*', 'table1.tid');
	$test->print();
	
    echo '</i>';
    
    $test->varReset();
    
    echo <<<EOH
    <br /><br />
    <h2 style="margin: 0px; padding: 0px;">Trial #5:</h2>
    <b>Experiment: Getting more custom with the where parameters.</b> <br />
    <b>Result:</b><br />
    <i>
EOH;

	$test = $db->tblproducts;
	$test->whereFldimageLike('/usr/images');
	$test->where('(fldTest = \'test\' && fldTimestamp < NOW() - 3600)');
	$test->get('table1.id', 'table2.*', 'table1.tid');
	$test->print();
	
    echo '</i>';
    
    $test->varReset();
    
    echo <<<EOH
    <br /><br />
    <h2 style="margin: 0px; padding: 0px;">Trial #6:</h2>
    <b>Experiment: Getting more custom with the where parameters.</b> <br />
    <b>Result:</b><br />
    <i>
EOH;

	$test = $db->tblproducts;
	$test->whereFldimageLike('/usr/images');
	$test->where('(fldTest = \'test\' && fldTimestamp < NOW() - 3600)');
	$test->get('table1.id', 'table2.*', 'table1.tid');
	$test->print();
	
    echo '</i>';
	
?>

output: 


Trial #1:
Experiment: Testing where fields with multiple operator types and out of order.
Code:
Result:
SELECT * FROM tblproducts WHERE fldtype = Array OR fldtest = Array && tbltest.fld = 'value' ORDER BY fldtest asc, fldtype desc LIMIT 1, 2

Trial #2:
Experiment: Testing joins and out of order where fields combined.
Result:
SELECT * FROM tblproducts JOIN table ON table.id = table1.id LEFT JOIN table ON table.id = table1.id RIGHT JOIN table ON table.id = table1.id WHERE fldtype = Array OR fldtest = Array && tbltest.fld = 'value' ORDER BY fldtest asc, fldtype desc LIMIT 1, 2

Trial #3:
Experiment: Testing individual select columns, and multiple where joins all out of order.
Result:
SELECT table1.id, table2.*, table1.tid FROM tblproducts WHERE fldtype = Array OR fldtest = Array && tbltest.fld = 'value' ORDER BY fldtest asc, fldtype desc LIMIT 1, 2

Trial #4:
Experiment: Supplying insufficient parameters
Result:
MyIO Exception Error
Message: Insufficient parameters for JOIN statement. Supplied 2 expected 3.
Stack Trace: #0 [internal function]: MyIODriver->__call('join', Array) #1 C:\Apache\htdocs\myio\index.php(86): MyIODriver->join('table', 'table.id') #2 {main}

SELECT table1.id, table2.*, table1.tid FROM tblproducts WHERE fldtype = Array OR fldtest = Array && tbltest.fld = 'value' ORDER BY fldtest asc, fldtype desc LIMIT 1, 2

Trial #5:
Experiment: Getting more custom with the where parameters.
Result:
SELECT table1.id, table2.*, table1.tid FROM tblproducts WHERE fldimage LIKE '%/usr/images%' AND (fldTest = 'test' && fldTimestamp < NOW() - 3600)

Trial #6:
Experiment: Getting more custom with the where parameters.
Result:
SELECT table1.id, table2.*, table1.tid FROM tblproducts WHERE fldimage LIKE '%/usr/images%' AND (fldTest = 'test' && fldTimestamp < NOW() - 3600)