【发布时间】:2019-01-31 14:11:16
【问题描述】:
我想从 SQLite3 文件中的表 dictonary 中随机选择一列。但我不知道为什么它会给我一个警告。(注意)
这是我写的代码:(部分)
<?php
class DB extends SQLite3{
function __construct($path){
return $this->open($path);
}
function randWord(){
//Randomize select a word from database.
$words = $this->query("select count(*) from 'dictonary';");
return $this->query("select * from 'dictonary' limit 1 offset ".mt_rand(0,$words-1).";")->fetchArray()['wholeWord'];
}
}
$database = new DB('storage.db');
echo json_encode([
'status'=>200,
'message'=>'Got an word!',
'data'=>[
'word'=>$database->randWord()
]
],JSON_PRETTY_PRINT);
$database->close();
这是回应:
<br />
<b>Notice</b>: Object of class SQLite3Result could not be converted to int in <b>D:\phpStudy\htdocs\Files\word-match\api.php</b> on line <b>17</b><br />
{
"status": 200,
"message": "Got an word!",
"data": {
"word": "\u5b66\u795e\u4e4b\u5973"
}
}
为什么?
【问题讨论】: