PHP 用のシングルトン データベース クラスを作成しました。そして、私はそれがうまく機能していると思っていましたが、実際にはそうではありませんでした。現在、3 つのクエリを含むページを作成しています。1 つはアルバムが存在するかどうかを確認するため、1 はユーザーがアルバムを所有しているかどうかを確認するため、もう 1 つはアルバムから写真を取得するためです。
3 番目のクエリでオブジェクトを設定しますが、最初の 2 つのクエリの結果もその配列にあるため、通知が表示されます。
例を次に示します。
Array
(
[0] => Array
(
[id] => 2
[name] => My new album 1
[slug] => my-new-album-1
[user_id] => 1
[views] => 0
[datecreated] => 2013/03/23 16:00:43
)
[1] => Array
(
[id] => 3
[name] => My new album 1
[slug] => my-new-album-1
[user_id] => 1
[views] => 0
[datecreated] => 2013/03/23 23:51:58
)
[2] => Array
(
[id] => 2
)
[3] => Array
(
[id] => 117
[title] =>
[location_id] =>
[date] => 2013-03-30 00:42:26
[user_id] => 1
[album_id] => 2
)
そして、これは私がクエリを実行して配列を返す方法です:
mysqli_conn::getInstance()->query($sql)->all_assoc()
これは、クエリを実行して結果を返すデータベース クラスの一部です。
public function query( $sql ){
$starttime = $this->time_to_float();
$this->query = mysqli_query($this->connection, $sql);
$endtime = $this->time_to_float();
$exectime = ($endtime - $starttime);
if (!$this->query){
throw new Exception(mysqli_error($this->connection));
} else {
$this->arQueryLog[] = array ( 'query' => $sql,
'exectime' => $exectime,
'affected_rows' => mysqli_affected_rows($this->connection),
'last_insert_id' => $this->lastID() );
}
return $this;
}
public function all_assoc ()
{
while($result = mysqli_fetch_assoc($this->query)){
$this->result[] = $result;
}
return $this->result;
}
最後のクエリ結果のみが結果配列にあるようにするにはどうすればよいですか?
ありがとう!!