PHP: How to fetch a single value from sqlite table
I am trying to access sqlite from PHP script. Not sure how to fetch a single value from table.
<?php
if ($dbhandle = sqlite_open('c:/sqlite/test.db', 0666, $sqliteerror))
{
$sql = "SELECT max (user_id) from persons";
$res = sqlite_query($dbhandle, $sql);
if (sqlite_num_rows($result)>0) {
echo sqlite_fetch_single($result) ;
}
}
?>
I am getting following error
Fatal error: Call to undefined function sqlite_open() in C:xampphtdocsfetch_db.php on line 3
Just to add i am using Sqlite3.And even if I use PDo function I am getting error
Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:xampphtdocsfetch_db.php on line 4
<?php
$db = new PDO("sqlite:c:/sqlite/test.db");
$q1 = echo $db->query('select mx(person_id) from persons');
while($r = $q1->fetchArray(SQLITE3_ASSOC))
{
echo $r['id'];
}
?>
You are getting error that there is no sqlite_open
function because you don't have installed SQLite on your PHP.
http://php.net/manual/en/sqlite.installation.php
From URL:
Since PHP 5.0 this extension was bundled with PHP. Beginning with PHP 5.4, this extension is available only via PECL.
Windows users must enable php_sqlite.dll inside of php.ini in order to use these functions. A DLL for this PECL extension is currently unavailable. See also the building on Windows section.
Windows builds must also enable PDO because as of PHP 5.1.0 it depends on it. So, php.ini will end up with something like this:
extension=php_pdo.dll
extension=php_sqlite.dll
链接地址: http://www.djcxy.com/p/69424.html
下一篇: PHP:如何从sqlite表中获取单个值