<?php
/*
http://coolpenguin.net/persistclass
for updates, documentation, tutorials
*/
// connect to database (executing demo 1)
require('demo1-connection.php');
// get connection object
$con = DbConnectionPool::instance()->getConnection();
// execute an insert
$sql = 'INSERT INTO TESTTABLE(testcolumn) VALUES("INSERTSUCCESS")';
$con->query($sql);
// execute an update, retrieving number of updated rows
$sql = 'UPDATE TESTTABLE SET testcolumn = "UPDATESUCCESS"';
$modifiedRows = $con->query($sql);
// or $con->getRowsNum()
// perform select, iterating result
$sql = 'SELECT testcolumn FROM TESTTABLE';
$con->query($sql);
while($row = $con->next()) {
$testColumn = $row['testcolumn'];
}
// putting the result rows into an array
$sql = 'SELECT testcolumn FROM TESTTABLE';
$rows = $con->queryResultArr($sql);
// selecting a single row
$sql = 'SELECT testcolumn FROM TESTTABLE';
$row = $con->queryFirstRow($sql);
// selecting the first column of the first row
$sql = 'SELECT count(*) FROM TESTTABLE';
$count = $con->queryFirstRowCol($sql);
// selecting an array containing all rows first columns
$sql = 'SELECT TESTID from TESTTABLE';
$ids = $con->queryFirstColumnSet($sql);
// retrieving the total number of rows returned
$sql = 'SELECT testcolumn FROM TESTTABLE';
$con->query($sql);
$resultCount = $con->getRowsNum();
// retrieving ID of last inserted row
$sql = 'INSERT INTO TESTTABLE(testcolumn) VALUES("INSERTSUCCESS")';
$con->query($sql);
$lastId = $con->getLastId();
// escaping database input
$dangerousData = '"; DROP TABLES';
$sql = 'INSERT INTO TESTTABLE(testcolumn) VALUES('. $con->escape($dangerousData) .')';
// retrieving database link
$dbLink = $con->getLink();
echo 'Test successful';
?>
|