简体   繁体   English

PHP sqlite3不显示行结果

[英]PHP sqlite3 not showing results from row

I have the following code that runs ok but if I want to show the records from the fetched array it doesn't and no error is displayed. 我有以下可以正常运行的代码,但是如果我想显示读取数组中的记录,则不会,也不会显示错误。

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$db = new SQLite3('db/ZIPDB.sl3');

if(!$db) {
  echo $db->lastErrorMsg();
}

$sql =<<<EOF
  SELECT id, zip, country FROM ZIPDB WHERE zip LIKE '%32038%';
EOF;

$ret = $db->query($sql);
$row = $ret->fetchArray(SQLITE3_ASSOC);

echo "The entire array: \n";
var_dump($row);
//echo "ID: $row['id']\n";
//echo "ZIP: $row['zip']\n";
//echo "Country: $row['country']\n";

$db->close();
?>

The array is displayed correctly as: 该数组正确显示为:

The entire array: array(3) { ["id"]=> string(6) "213" ["zip"]=> string(4) "32038" ["country"]=> string(13) "UNITED STATES" } 整个数组:array(3){[“ id”] => string(6)“ 213” [“ zip”] => string(4)“ 32038” [“ country”] => string(13)“ UNITED状态” }

If I uncomment the lines after var_dump() I get no output and no error either. 如果取消注释var_dump()之后的行,则不会输出也不会出错。 I must specify the output is a single row not multiple so I would use a foreach loop. 我必须指定输出是单行而不是多行,因此我将使用foreach循环。 Any idea what's wrong? 知道有什么问题吗?

EDIT: 编辑:

Sorry, I think I forgot to: 对不起,我想我忘记了:

echo "ID: " .$row['id']. "\n";
echo "ZIP: " .$row['zip']. "\n";
echo "Country: " .$row['country']. "\n";

Now works... I think I should close the question. 现在有效...我想我应该结束这个问题。

Since no answer, I will answer myself with a working version of the little snippet: 由于没有答案,因此我将以小片段的工作版本来回答自己:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$db = new SQLite3('db/ZIPDB.sl3');

if(!$db) {
  echo $db->lastErrorMsg();
}

$sql =<<<EOF
  SELECT id, zip, country FROM ZIPDB WHERE zip LIKE '%32038%';
EOF;

$ret = $db->query($sql);
$row = $ret->fetchArray(SQLITE3_ASSOC);

echo "The entire array: \n";
var_dump($row);
echo "ID: " .$row['id']. "\n";
echo "ZIP: " .$row['zip']. "\n";
echo "Country: " .$row['country']. "\n";

$db->close();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM