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>";
?>
sqlite_field_name
(PHP 5, PECL sqlite:1.0-1.0.3)
sqlite_field_name — Retorna o nome de um campo em particular.
Descrição
string sqlite_field_name
( resource $result
, int $indice_campo
)
Dado um numero de coluna, indice_campo, retorna o nome do campo no resultado result .
sqlite_field_name
rrf5000 at psu dot edu
22-Jun-2007 01:03
22-Jun-2007 01:03
