douwen7905 2016-04-29 22:39
浏览 26
已采纳

覆盆子上的数据库路径

I'm new in raspberry and I'm trying to read a simple database from a php page but there is something wrong: I can't read the database content: Here the php page code:

<!DOCTYPE html>
<html>
<body>
<H1>Test Database</H1>

<?php

$sq = sqlite_open('miodatabase.db', 0666, $sqlite_error);

if(!$sq)
{
   die(“Errore Sqlite: “.$sqlite_error);
}

$result = sqlite_query($sq, 'select * from test');
while($data = sqlite_fetch_array($result))
{
   echo $data[‘nome’];
}
sqlite_close($sq);
?>

</body>
</html>

The database is "miodatabase" that contains a table called "test". I put the database in \var\www\html folder (is correct?) but when I open the page I see a blank page. I'm sure the database contains the table (tested with sqlite3 commands) and the table contains one row. Where I need to put the database? Why I can't see nothing? Thanks

  • 写回答

2条回答 默认 最新

  • douhui3305 2016-04-30 08:27
    关注

    I solved: I type again the command

    sudo apt-get install php5-sqlite
    sudo /etc/init.d/apache2 restart
    

    and then I can see in the php info the sections about sqlite3. The I update my php page like this:

    //Enable show error
    ini_set('display_errors', 'On');
    error_reporting(E_ALL|E_STRICT);
    
    
    $db = new SQLite3("miodatabase.db");
    
    $sql_select='SELECT * FROM test'; 
    $result=$db->query($sql_select); 
    
    echo "<table border='1'>"; 
    echo "<tr>"; 
    $numColumns=$result->numColumns(); 
    for ($i = 0; $i < $numColumns; $i++) 
    { 
        $colname=$result->columnName($i); 
        echo "<th>$colname</th>"; 
    } 
    echo "</tr>"; 
    while($row = $result->fetchArray(SQLITE3_NUM)) 
    { 
        echo "<tr>"; 
        for ($i = 0; $i < $numColumns; $i++) 
        { 
            $value=$row[$i]; 
            echo "<th>$value</th>"; 
        } 
        echo "</tr>"; 
    } 
    echo "</table>";
    

    To open the database I use now

    $db = new SQLite3("miodatabase.db");
    

    because the sqlite_open is not supported by this version of sqlite. Now all works correctly

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图