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).

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

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂