duancheng6500 2014-06-20 18:22
浏览 37
已采纳

代码适用于Windows,相同的代码在Linux上不起作用

I've got a website I'm developping with PHP5 + SQLite3, It worls like a charm on WAMP on my computer, but for some reason it doesn't work on my Debian Server, I don't get any error, I can access my db via adminer.php, but my own PHP code doesn't seem to be able to access it.

Here are the 2 last lines of the error log :

[Fri Jun 20 01:33:37 2014] [error] [client 93.2.64.89] PHP Warning: SQLite3::query(): Unable to prepare statement: 1, no such table: morceaux in /home/sim/www/gaec/sqlite-read.php on line 12   
[Fri Jun 20 01:33:37 2014] [error] [client 93.2.64.89] PHP Fatal error: Call to a member function fetchArray() on a non-object in /home/sim/www/gaec/sqlite-read.php on line 14 

And here is my DB-test php file :

<?php
$dbname='viandes.db3';
$mytable ="morceaux";

if(!class_exists('SQLite3'))
 die("SQLite 3 NOT supported.");

$base=new SQLite3($dbname, 0666); 

$query = "SELECT DISTINCT Animal FROM $mytable WHERE LENGTH(Animal)>0";
$results = $base->query($query);

while ($row = $results->fetchArray())
 {
    if(count($row)>0)
     {
        $title = $row['Animal'];
        echo "</br> $title </br>";
     }
    else
     {
        echo "Can't access $mytable table.";
     }
  }
?>
  • 写回答

1条回答 默认 最新

  • dongzhi1949 2014-06-20 19:13
    关注

    From the docs:

    public SQLite3::__construct ( string $filename [, int $flags [, string $encryption_key ]] )

    Instantiates an SQLite3 object and opens a connection to an SQLite 3 database. If the build includes encryption, then it will attempt to use the key.

    Parameters

    filename Path to the SQLite database, or :memory: to use in-memory database.

    flags Optional flags used to determine how to open the SQLite database. By default, open uses SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE.

    SQLITE3_OPEN_READONLY: Open the database for reading only.

    SQLITE3_OPEN_READWRITE: Open the database for reading and writing.

    SQLITE3_OPEN_CREATE: Create the database if it does not exist.

    By passing 0666 you're in fact passing SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE which would create an empty database if the file does not exist. Those flags are not file permissions.

    Most probably your database filename differs in case from that in your code. Windows ignores case and opens the database while Linux creates a new database (and hence cannot find the table your want there).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题