note 75934 deleted from function.sqlite-field-name by cmb

From: Date: Mon, 02 Nov 2020 15:00:33 +0000
Subject: note 75934 deleted from function.sqlite-field-name by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215737@lists.php.net to get a copy of this message
Note Submitter: rrf5000 at psu dot edu ---- 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>"; ?>

« previous php.notes (#215737) next »