note 75934 added to function.sqlite-field-name

From: Date: Fri, 22 Jun 2007 08:03:13 +0000
Subject: note 75934 added to function.sqlite-field-name
Groups: php.notes 
Request: Send a blank email to php-notes+get-127883@lists.php.net to get a copy of this message
While working with SQLite using its object-oriented mode, I found need to display a column/field name without knowing what it was in advance. I couldn't find any examples on the Internet, just this document. So, for anyone who happens to need to do this, here's an example. <?php $db = "db/database.sqlite"; // create new database (OO interface) $dbo = new SQLiteDatabase("$db"); // create table foo and insert sample data $dbo->query(" CREATE TABLE foo(id INTEGER PRIMARY KEY, name CHAR(255)); INSERT INTO foo (name) VALUES('Ilia1'); INSERT INTO foo (name) VALUES('Ilia2'); INSERT INTO foo (name) VALUES('Ilia3'); "); $query = "SELECT * FROM foo;"; $result = $dbo->query($query) or die("Error in query"); echo " <table border='1' cellpadding='10'> <tr> <td>".$result->fieldName(0)."</td> <td>".$result->fieldName(1)."</td> </tr>"; // iterate through the retrieved rows while ($result->valid()) { // fetch current row $row = $result->current(); echo " <tr> <td>".$row[0]."</td> <td>".$row[1]."</td> </tr>"; // proceed to next row $result->next(); } echo "</table>"; ?> ---- Server IP: 64.71.164.2 Probable Submitter: 69.248.69.122 ---- Manual Page -- http://www.php.net/manual/en/function.sqlite-field-name.php Edit -- https://master.php.net/note/edit/75934 Del: integrated -- https://master.php.net/note/delete/75934/integrated Del: useless -- https://master.php.net/note/delete/75934/useless Del: bad code -- https://master.php.net/note/delete/75934/bad+code Del: spam -- https://master.php.net/note/delete/75934/spam Del: non-english -- https://master.php.net/note/delete/75934/non-english Del: in docs -- https://master.php.net/note/delete/75934/in+docs Del: other reasons-- https://master.php.net/note/delete/75934 Reject -- https://master.php.net/note/reject/75934 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#127883) next »