<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7722999210532317696</id><updated>2011-12-20T12:18:34.190+01:00</updated><category term='rollback'/><category term='download'/><category term='executing queries'/><category term='transactions'/><category term='select'/><category term='live examples'/><category term='running queries'/><category term='commit'/><category term='fetching data'/><category term='features'/><category term='information'/><category term='contribute'/><category term='first steps'/><category term='web site'/><category term='summary'/><category term='savepoint'/><category term='help'/><category term='basic usage'/><title type='text'>LIZ DB - PHP5 powerful and flexible database connectivity API</title><subtitle type='html'>LIZ DB is highly advanced set of interfaces of high abstraction level that allows programmer to create easily rich database applications (including stored procedures, sophisticated transactions, and more) in &lt;b&gt;PHP5&lt;/b&gt;.
&lt;br/&gt;
LIZ DB comes with a full &lt;b&gt;MySQL5&lt;/b&gt; implementation of all interfaces, and can be extended to support &lt;b&gt;any&lt;/b&gt; database.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7722999210532317696.post-4500349914433274708</id><published>2007-09-19T08:05:00.000+02:00</published><updated>2007-09-19T08:34:36.840+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='transactions'/><category scheme='http://www.blogger.com/atom/ns#' term='savepoint'/><category scheme='http://www.blogger.com/atom/ns#' term='commit'/><category scheme='http://www.blogger.com/atom/ns#' term='live examples'/><category scheme='http://www.blogger.com/atom/ns#' term='rollback'/><title type='text'>Transactions handling in LIZ DB</title><content type='html'>In today's article I will present transaction handling in LIZ DB.&lt;br /&gt;&lt;br /&gt;There are two ways developers may handle their transactions:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;automatic - managed by LIZ DB&lt;/li&gt;&lt;li&gt;programmatic - developers must commit, rollback all transactions themselves&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-size:130%;"&gt;1. LIZ DB managed transactions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;LIZ DB supports two automatic behaviours, those can be turn on/off by passing true or false values to one of following methods:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function SetAutoCommit($commit = true)&lt;/span&gt; - data will be committed after each INSERT, UPDATE or DELETE statement&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function SetCommitOnClose($commit = true)&lt;/span&gt; - all data will be committed at the end of current session&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Default MySQLimp settings are:&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;private $CommitOnClose = true;&lt;br /&gt;private $AutoCommit = false;&lt;br /&gt;&lt;/pre&gt; &lt;span style="font-weight: bold;"&gt;INFO&lt;br /&gt;&lt;/span&gt;These two behaviours are mutually explicit! If both set to true, auto commit will work.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;INFO&lt;/span&gt;&lt;br /&gt;MySQL supports transactions only when InnoDB engine is being used!&lt;br /&gt;MyISAM or any other engines do not support transactions.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;Examples of usage.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example 1. LIZ DB managed transactions.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db-&gt;SetAutoCommit(); // default value true will be used&lt;br /&gt;$db-&gt;SetAutoCommit(true); // same as above&lt;br /&gt;$db-&gt;SetAutoCommit(false); // no auto commits after DML statements&lt;br /&gt;// if auto commit is set to false, below code will work&lt;br /&gt;// all data will be committed on connection close&lt;br /&gt;$db-&gt;SetCommitOnClose(true); // default value true will be used&lt;br /&gt;$db-&gt;SetCommitOnClose(); // same as above&lt;br /&gt;// now, data won't be committed on connection close&lt;br /&gt;$db-&gt;SetCommitOnClose(false) &lt;/pre&gt;&lt;span style="font-size:130%;"&gt;&lt;br /&gt;2. User managed transactions&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;LIZ DB offers following methods for managing transactions programmatic way:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function StartTransaction()&lt;/span&gt; - starts transaction&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function Commit()&lt;/span&gt; - commits all DML statements executed in current transaction&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function AbortTransaction()&lt;/span&gt; - rollbacks all changes made to database in current transaction&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function SetSavePoint($name)&lt;/span&gt; - sets a new logical savepoint within current transaction&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public function RollbackToSavePoint($name)&lt;/span&gt; - rollbacks all changes made to database to given logical savepoint&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Examples of usage.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example 2. Basic transaction handling.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db = new MySQLimp($config);&lt;br /&gt;&lt;br /&gt;// start the transaction&lt;br /&gt;$db-&gt;StartTransaction();&lt;br /&gt;&lt;br /&gt;$chars = "some text";&lt;br /&gt;$int = mt_rand();&lt;br /&gt;$double = mt_rand() / mt_getrandmax();&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$newId = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;echo 'new record id: ' . $newId . "\n";&lt;br /&gt;&lt;br /&gt;// rollback current transaction&lt;br /&gt;// all changes will be rejected&lt;br /&gt;$db-&gt;Rollback();&lt;br /&gt;&lt;br /&gt;// explicitly begin new transaction&lt;br /&gt;$db-&gt;StartTransaction();&lt;br /&gt;&lt;br /&gt;$chars = "some other text";&lt;br /&gt;$int = mt_rand();&lt;br /&gt;$double = mt_rand() / mt_getrandmax();&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$newId = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;echo 'second new record id: ' . $newId . "\n";&lt;br /&gt;&lt;br /&gt;// after executing Commit method, all changes&lt;br /&gt;// made within current transaction will be&lt;br /&gt;// visible to other users&lt;br /&gt;$db-&gt;Commit();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Example 3. Transaction savepoints handling.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db = new MySQLimp($config);&lt;br /&gt;&lt;br /&gt;// explicitly start new transaction&lt;br /&gt;$db-&gt;StartTransaction();&lt;br /&gt;&lt;br /&gt;// will store IDs of newly inserted records&lt;br /&gt;$ids = array();&lt;br /&gt;&lt;br /&gt;$chars = "some text";&lt;br /&gt;$int = mt_rand();&lt;br /&gt;$double = mt_rand() / mt_getrandmax();&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$ids[] = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;// dirty record&lt;br /&gt;echo 'first new record id: ' . $ids[0] . "\n";&lt;br /&gt;&lt;br /&gt;$chars = "some other text";&lt;br /&gt;$int = mt_rand();&lt;br /&gt;$double = mt_rand() / mt_getrandmax();&lt;br /&gt;&lt;br /&gt;// everything that will be executed from now on&lt;br /&gt;// can be rollbacked to this point&lt;br /&gt;$db-&gt;SetSavePoint('beforeInsertingSecondRecord');&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$ids[] = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;// second dirty record&lt;br /&gt;echo 'second new record id: ' . $ids[1] . "\n";&lt;br /&gt;&lt;br /&gt;// rollback to 'beforeInsertingSecondRecord' savepoint&lt;br /&gt;// second record will be rejected&lt;br /&gt;$db-&gt;RollbackToSavePoint('beforeInsertingSecondRecord');&lt;br /&gt;&lt;br /&gt;// record was rejected, this will return empty set&lt;br /&gt;$db-&gt;Query = "SELECT `id` FROM `lizdb_test_table` WHERE `id` = '{$ids[1]}'";&lt;br /&gt;$second = $db-&gt;SelectOne();&lt;br /&gt;&lt;br /&gt;echo 'Is rec no ' . $ids[1] .  ' in db now? ' . !empty($second) . '';&lt;br /&gt;&lt;br /&gt;// the first one is still dirty (either not committed or not rollbacked)&lt;br /&gt;// abort transaction and rollback all uncommitted data&lt;br /&gt;$db-&gt;AbortTransaction();&lt;br /&gt;&lt;br /&gt;// verify if both records do not exist in database&lt;br /&gt;$ids = implode(',', $ids);&lt;br /&gt;$db-&gt;Query = "SELECT * FROM `lizdb_test_table` WHERE `id` IN ({$ids})";&lt;br /&gt;$added  = $db-&gt;Select();&lt;br /&gt;&lt;br /&gt;// both records are 'wiped out' without any trace, count($added) == 0&lt;br /&gt;echo 'No of added records: ' . count($added) . '';&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. Live examples&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Live examples are available at &lt;a href="https://vega.eti.pg.gda.pl/%7Exh/lizdb_test/examples/transactions.php"&gt;LIZ DB - Transactions API Examples&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;INFO&lt;br /&gt;&lt;/span&gt;Currently live examples server does not support MySQL InnoDB storage and transactions.&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7722999210532317696-4500349914433274708?l=lizdb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/4500349914433274708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7722999210532317696&amp;postID=4500349914433274708' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/4500349914433274708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/4500349914433274708'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/2007/09/transactions-handling-in-liz-db.html' title='Transactions handling in LIZ DB'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7722999210532317696.post-2166859788140093886</id><published>2007-09-18T17:34:00.000+02:00</published><updated>2007-09-19T08:34:51.270+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='running queries'/><category scheme='http://www.blogger.com/atom/ns#' term='live examples'/><category scheme='http://www.blogger.com/atom/ns#' term='executing queries'/><title type='text'>Executing queries</title><content type='html'>Today I will show how to execute queries in LIZ DB.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. LIZ DB RunQuery API&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;All non-SELECT statements are executed by calling only one method. The method is:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;public function RunQuery()&lt;/span&gt; - executes &lt;span style="font-weight: bold;"&gt;any&lt;/span&gt; valid DDL (CREATE, ALTER, DROP) or DML (INSERT, UPDATE, DELETE) statement&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;INFO&lt;/span&gt;&lt;br /&gt;Before invoking this functions, public field Query should be set to valid SQL statement otherwise LIZ DB will throw LIZDBException.&lt;br /&gt;LIZDBException exception will be also thrown if Query will contain SELECT statement.&lt;br /&gt;&lt;br /&gt;The returned value differs according to the type of executed statement.&lt;br /&gt;Juxtaposition of types of statements and returned values is as follows:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;INSERT&lt;/span&gt; - returns ID of newly created record (if table has an auto increment &lt;span id="misspell-10" class="unmark"&gt;primary&lt;/span&gt; key, otherwise returns null)&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;UPDATE/DELETE&lt;/span&gt; - returns number of updated/deleted records&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;CREATE, ALTER, DROP, GRANT, REVOKE&lt;/span&gt; - returns true or false whether the statement was successfully executed&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Examples of usage.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Example 1. Inserting new records.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$ids = array();&lt;br /&gt;&lt;br /&gt;$chars = "some text";&lt;br /&gt;$int = mt_rand();&lt;br /&gt;$double = mt_rand() / mt_getrandmax();&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$ids[] = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;echo 'First new record id: ' . $ids[0] . "\n";&lt;br /&gt;&lt;br /&gt;$chars = "some other text";&lt;br /&gt;$int = mt_rand();&lt;br /&gt;$double = mt_rand() / mt_getrandmax();&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$ids[] = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;echo 'Second new record id: ' . $ids[1] . "\n";&lt;br /&gt;&lt;/pre&gt;Example 2. Updating and deleting records.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db-&gt;Query = "UPDATE `lizdb_test_table` SET `double_column` = 0.0 WHERE `id` = '{$ids[0]}'";&lt;br /&gt;$updatedRows = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;echo 'No of updated rows: ' . $updatedRows . "\n";&lt;br /&gt;&lt;br /&gt;$ids = implode(',', $ids);&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "DELETE FROM `lizdb_test_table` WHERE `id` IN ({$ids})";&lt;br /&gt;$deletedRows = $db-&gt;RunQuery();&lt;br /&gt;&lt;br /&gt;echo 'No of deleted rows: ' . $deletedRows . "\n";&lt;br /&gt;&lt;/pre&gt;Example 3. Executing DDL statements.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db-&gt;Query = "CREATE TABLE `t` (`f` int)";&lt;br /&gt;&lt;br /&gt;if ($db-&gt;RunQuery()) {&lt;br /&gt;    echo "New table successfully created\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "DROP TABLE IF EXISTS `t`";&lt;br /&gt;&lt;br /&gt;if ($db-&gt;RunQuery()) {&lt;br /&gt;    echo "table deleted successfully\n";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. Live examples&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Live examples are available at &lt;a href="http://vega.eti.pg.gda.pl/%7Exh/lizdb_test/examples/run_queries.php"&gt;LIZ DB - RunQuery API Examples&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7722999210532317696-2166859788140093886?l=lizdb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/2166859788140093886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7722999210532317696&amp;postID=2166859788140093886' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/2166859788140093886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/2166859788140093886'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/2007/09/executing-queries.html' title='Executing queries'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7722999210532317696.post-9197511678721269141</id><published>2007-09-17T14:18:00.000+02:00</published><updated>2007-09-19T08:34:09.295+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fetching data'/><category scheme='http://www.blogger.com/atom/ns#' term='live examples'/><category scheme='http://www.blogger.com/atom/ns#' term='select'/><title type='text'>Fetching data from database</title><content type='html'>In today's post I will present basic ways of fetching data from database in LIZ DB.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. LIZ DB SELECT API&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For fetching data from database there are three different functions, these are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;public function SelectOne()&lt;/span&gt; - fetches a record, returns an associative array that represents given record&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;public function Select()&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt; - fetches a set of records, returns an array of associative arrays (records)&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold; font-style: italic;"&gt;public function SelectColumn()&lt;/span&gt; - fetches a set of given column's values, returns an array of column's values&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;INFO&lt;/span&gt;&lt;br /&gt;Before invoking any of the Select functions, public field Query should be set to valid SELECT statement otherwise LIZ DB will throw LIZDBException.&lt;br /&gt;LIZDBException exception will be also thrown if Query will contain other statements than SELECT (like INSERT, CREATE, DROP, etc.).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Examples of usage.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example 1. Fetching single records.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db-&gt;Query = 'SELECT * FROM `lizdb_test_table` ORDER BY id DESC LIMIT 1';&lt;br /&gt;$record = $db-&gt;SelectOne();&lt;br /&gt;&lt;br /&gt;// $record is an associative array&lt;br /&gt;echo 'Last record is: ';&lt;br /&gt;echo $record['id'] . ', ' . $record['char_column'] . ', ' . $record['int_column'] . ', ' .$record['double_column'];&lt;br /&gt;&lt;/pre&gt;Example 2. Fetching sets of records.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db-&gt;Query = 'SELECT * FROM `lizdb_test_table`';&lt;br /&gt;$records = $db-&gt;Select();&lt;br /&gt;&lt;br /&gt;// $records is an array of associative arrays&lt;br /&gt;foreach($records as $r) {&lt;br /&gt;echo $r['id'] . ', ' . $r['char_column'] . ', ' . $r['int_column'] . ', ' .$r['double_column'];&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Example 3. Fetching sets of given column's values.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;$db-&gt;Query = 'SELECT `double_column` FROM `lizdb_test_table` WHERE `double_column` &lt; negativedoubles =" $db-"&gt;SelectColumn();&lt;br /&gt;&lt;br /&gt;// $negativeDoubles is an ordinary array&lt;br /&gt;echo 'negative doubles are:' . implode(',', $negativeDoubles);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. Live examples&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Live examples are available at &lt;a href="http://vega.eti.pg.gda.pl/%7Exh/lizdb_test/examples/selects.php"&gt;LIZ DB - SELECT API Examples&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7722999210532317696-9197511678721269141?l=lizdb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/9197511678721269141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7722999210532317696&amp;postID=9197511678721269141' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/9197511678721269141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/9197511678721269141'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/2007/09/fetching-data-from-database.html' title='Fetching data from database'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7722999210532317696.post-44944084199708133</id><published>2007-09-16T09:32:00.000+02:00</published><updated>2007-09-19T08:40:23.631+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='basic usage'/><category scheme='http://www.blogger.com/atom/ns#' term='running queries'/><category scheme='http://www.blogger.com/atom/ns#' term='executing queries'/><category scheme='http://www.blogger.com/atom/ns#' term='select'/><category scheme='http://www.blogger.com/atom/ns#' term='first steps'/><title type='text'>First steps with LIZ DB</title><content type='html'>This article introduces LIZ DB basics.&lt;br /&gt;&lt;br /&gt;LIZ DB is very easy to install. All You have to do is simply download the newest version and unzip downloaded archive to Your working directory.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;1. Defining LIZDB_PATH constant&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First, in order to start working with LIZ DB we need to define LIZDB_PATH that points to the directory in which we have installed (unzipped) our archive.&lt;br /&gt;&lt;br /&gt;Example 1. Defining LIZDB_PATH.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;// LIZDB_PATH must point to directory where LIZ DB is installed&lt;br /&gt;define('LIZDB_PATH',  '/home/xh/public_html/lizdb_test/LIZDB');&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;LIZDB_PATH can be also set dynamically, the below code will work&lt;br /&gt;assuming LIZ DB was installed into current directory.&lt;br /&gt;&lt;br /&gt;Example 2. Automatic defining LIZDB_PATH.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;if (false == is_dir(LIZDB_PATH)) {&lt;br /&gt;define('LIZDB_PATH',  getcwd() . '/LIZDB');&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we're ready to create DB objects and connect to our database.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;2. Creating DB object&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Currently LIZ DB 2.0 provides implementation only for MySQL5.&lt;br /&gt;We need to include class definition and create its instance.&lt;br /&gt;&lt;br /&gt;There is MySQLimp class (imp stands for improved, not implementation) in&lt;br /&gt;LIZDB_PATH . '/classes/MySQLimp.inc.php' file.&lt;br /&gt;&lt;br /&gt;MySQLimp's constructor expects associative array that must define following:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;server&lt;/span&gt; -  name or IP of MySQL server&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;user&lt;/span&gt; - username for &lt;span id="misspell-25" class="unmark"&gt;authorisation&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;passwd&lt;/span&gt; - password for &lt;span id="misspell-25" class="unmark"&gt;authorisation&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-weight: bold;"&gt;database&lt;/span&gt; - database to connect to&lt;/li&gt;&lt;/ul&gt;All MySQLimp code should be surrounded by try/catch blocks.&lt;br /&gt;There are two types of exceptions that can be thrown during script's execution:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Exception - &lt;span style="font-weight: bold;"&gt;all&lt;/span&gt; generic PHP5 exceptions&lt;br /&gt;&lt;/li&gt;&lt;li&gt;LIZDBException - thrown explicitly by LIZ DB, these exceptions are strictly linked with database errors&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Example 3. Creating DB objects.&lt;br /&gt;&lt;pre style="background-color: silver;"&gt;require LIZDB_PATH . '/classes/MySQLimp.inc.php';&lt;br /&gt;// change Your settings!&lt;br /&gt;// or run sql/create_user.sql to create lizdb user&lt;br /&gt;$config = array();&lt;br /&gt;$config['server'] = 'localhost';&lt;br /&gt;$config['user'] = 'lizdb';&lt;br /&gt;$config['passwd'] = 'lizdb';&lt;br /&gt;$config['database'] = 'test';&lt;br /&gt;&lt;br /&gt;try {&lt;br /&gt;    $db = new MySQLimp($config);&lt;br /&gt;&lt;br /&gt;    $db-&gt;CloseConnection();&lt;br /&gt;} catch (LIZDBException $e) {&lt;br /&gt;    echo $e-&gt;getMessage() . "\n";&lt;br /&gt;    echo $e-&gt;GetQuery();&lt;br /&gt;} catch (Exception $e) {&lt;br /&gt;    echo $e-&gt;getMessage();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;3. Basic fields and methods&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There is only one public field in MySQLimp class:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public $Query&lt;/span&gt; - this field stores SQL statement to be executed (&lt;span style="font-weight: bold;"&gt;any&lt;/span&gt; valid MySQL statement!)&lt;/li&gt;&lt;/ul&gt;There are few methods that execute queries and handle their results, these are:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public Select()&lt;/span&gt; - returns array of records&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public SelectOne()&lt;/span&gt; - returns single record&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public SelectColumn()&lt;/span&gt; - return array of given column's values&lt;/li&gt;&lt;li&gt;&lt;span style="font-style: italic; font-weight: bold;"&gt;public RunQuery()&lt;/span&gt; - runs INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, GRANT, REVOKE, and more...&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Usage of these methods will be covered by upcoming articles.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example 4. The very basic usage of SelectOne and RunQuery methods.&lt;pre style="background-color: silver;"&gt;$db-&gt;Query = 'SELECT * FROM `lizdb_test_table` ORDER BY id DESC LIMIT 1';&lt;br /&gt;$record = $db-&gt;SelectOne();&lt;br /&gt;&lt;br /&gt;$db-&gt;Query = "INSERT INTO `lizdb_test_table` VALUES (NULL, '{$chars}', {$int}, {$double})";&lt;br /&gt;$newId = $db-&gt;RunQuery();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Stay tuned for more examples!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7722999210532317696-44944084199708133?l=lizdb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/44944084199708133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7722999210532317696&amp;postID=44944084199708133' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/44944084199708133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/44944084199708133'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/2007/09/first-steps-with-liz-db.html' title='First steps with LIZ DB'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7722999210532317696.post-6731738841488014410</id><published>2007-09-14T15:50:00.000+02:00</published><updated>2007-09-14T16:03:48.984+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='contribute'/><category scheme='http://www.blogger.com/atom/ns#' term='help'/><title type='text'>Contribute to the LIZ DB project!</title><content type='html'>LIZ DB is a non-commercial open-source project, developed under the PHP License that can be used and modified freely by everyone.&lt;br /&gt;&lt;br /&gt;LIZ DB currently provides implementation of its interfaces only for MySQL5 database.&lt;br /&gt;&lt;br /&gt;I encourage every developer that finds LIZ DB database connectivity approach attractive to write implementations for other vendors like PostgreSQL, Oracle, IBM DB2, and other.&lt;br /&gt;&lt;br /&gt;I'm looking forward to hear from You!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7722999210532317696-6731738841488014410?l=lizdb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/6731738841488014410/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7722999210532317696&amp;postID=6731738841488014410' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/6731738841488014410'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/6731738841488014410'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/2007/09/contribute-to-liz-db-project.html' title='Contribute to the LIZ DB project!'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7722999210532317696.post-528588285161013231</id><published>2007-09-14T09:44:00.000+02:00</published><updated>2007-09-16T10:50:45.171+02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='summary'/><category scheme='http://www.blogger.com/atom/ns#' term='download'/><category scheme='http://www.blogger.com/atom/ns#' term='features'/><category scheme='http://www.blogger.com/atom/ns#' term='live examples'/><category scheme='http://www.blogger.com/atom/ns#' term='information'/><category scheme='http://www.blogger.com/atom/ns#' term='web site'/><title type='text'>Project's summary and features!</title><content type='html'>LIZ DB is highly advanced set of interfaces of high abstraction level that allows programmer to create easily rich database applications (including stored procedures, sophisticated transactions, and more) in PHP5.&lt;br /&gt;&lt;br /&gt;LIZ DB comes with a full MySQL5 implementation of all interfaces, and can be extended to support &lt;span style="font-weight: bold;"&gt;any&lt;/span&gt; database.&lt;br /&gt;&lt;br /&gt;Built-in MySQL implementation of LIZ DB allows programmer to:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;fetch data in various ways: single record, set of records, set of column's values&lt;/li&gt;&lt;li&gt;prepare and execute statements in Java-like way&lt;/li&gt;&lt;li style="color: rgb(255, 0, 0); font-weight: bold;"&gt;prepare and call stored procedures and functions with IN, INOUT, OUT parameters support!&lt;/li&gt;&lt;li style="color: rgb(0, 0, 0);"&gt;manage sophisticated transactions, supports two LIZ DB managed modes: autocommit and commit on close. Also, there are means to manage transactions by developers, those are: commits, rollbacks, savepoints, and rollbacks to savepoints.&lt;/li&gt;&lt;/ul&gt;Important links:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://sourceforge.net/projects/lizdb"&gt;LIZ DB Project's Summary&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://sourceforge.net/project/platformdownload.php?group_id=177776"&gt;LIZ DB Downloads&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://vega.eti.pg.gda.pl/%7Exh/lizdb_test/examples/"&gt;LIZ DB &lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;Live&lt;/span&gt; Examples!&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7722999210532317696-528588285161013231?l=lizdb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lizdb.blogspot.com/feeds/528588285161013231/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7722999210532317696&amp;postID=528588285161013231' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/528588285161013231'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7722999210532317696/posts/default/528588285161013231'/><link rel='alternate' type='text/html' href='http://lizdb.blogspot.com/2007/09/liz-db-blog-starts.html' title='Project&apos;s summary and features!'/><author><name>Łukasz Budnik</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_DutjqqRLzpg/SLJc4ZYBFSI/AAAAAAAAB6M/ZI7Szj9p45U/S220/profil.jpg'/></author><thr:total>0</thr:total></entry></feed>
