Home > php教程 > PHP源码 > 用PDO连接SQLite3

用PDO连接SQLite3

PHP中文网
Release: 2016-05-25 17:11:45
Original
932 people have browsed it

[PHP]代码

<?php
    $db = new PDO(&#39;sqlite:test.sqlite&#39;);
    if ($db){
        echo &#39;OK!SQLite 连接成功!<br />&#39;;
    }else{
        echo &#39;Error!SQLite 连接失败,请检查!<br />&#39;;
    }

    echo "<br />查询输出:<br />";

    $db->exec("INSERT INTO news (id,title,date) VALUES ( &#39;2&#39;, &#39;MySQL&#39;, &#39;".date(&#39;Y-m-d H:i:s&#39;)."&#39;)");

    foreach ($db->query(&#39;SELECT id,title,date FROM news;&#39;) as $row)
    {
        echo $row[0].&#39; / &#39;.$row[1].&#39; / &#39;.$row[2].&#39;<br />&#39;;
    }
?>
Copy after login

                   

                   

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template