How to connect to a SQLite3 db with PHP

前端 未结 3 834
庸人自扰
庸人自扰 2020-12-09 02:22

I\'m new to SQLite3 and PHP and was wondering whether and how I could connect to a SQLite3 database with PHP.

How would I get the data from the db and would it be po

相关标签:
3条回答
  • 2020-12-09 02:45

    SQLite is enabled by default with PHP. You have to use the built-in class SQLite3 (you will find some examples on this page).

    0 讨论(0)
  • 2020-12-09 02:48

    This is the best way I have found and I got it directly from the sqlite website:

    <?php
    $db = new SQLite3('sqlite3db.db');
    
    $results = $db->query('select * from db');
    while ($row = $results->fetchArray()) {
    var_dump($row);
    }
    ?>
    

    Also if you're looking to include the php results into html like a table cell or something, go as such:

    $results = $db->query('select * from db');
    
    ?>
    
    
    
    <?php  while ($row = $results2->fetchArray()) {?> 
    <td><h4><?php echo $row['id'];?></h4></td>
    <?php } ?>
    
    0 讨论(0)
  • 2020-12-09 03:03
    <?php
    $db = new SQLite3('mysqlitedb.db');
    
    $results = $db->query('SELECT bar FROM foo');
    while ($row = $results->fetchArray()) {
        var_dump($row);
    }
    ?>
    

    Taken from here: PHP: SQLite3::query - Manual

    0 讨论(0)
提交回复
热议问题