Home  >  Article  >  php教程  >  用PDO连接SQLite3

用PDO连接SQLite3

PHP中文网
PHP中文网Original
2016-05-25 17:11:45911browse

[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;;
    }
?>

                   

                   

Statement:
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
Previous article:反缓存头部信息Next article:PHP网站短信接口源代码