私は私のプロジェクトで使用するためにカスタムデータベースクラスを構築していますに移動しmysql_fetch_assocメソッドを取得します。私は、whileループ内で呼び出すときしかし、それは次のレコードに移動していない、fetchAssoc()メソッドを構築しました。スクリプトがタイムアウトするまで、最初のレコードを繰り返し呼び出します。以下
は、関連するコードです:PHP MYSQLデータベースクラス - 次のレコード
方法:
function runQuery($q)
{
$this->numQueries++;
$this->query = ($q);
$this->setResult($q);
$this->result;
}
function fetchAssoc($q = NULL)
{
if($q == NULL)
{
$q = $this->query;
}
$this->setResult($q);
if($q == NULL || mysql_num_rows($this->result) < 1)
{
return NULL;
}
else
{
return mysql_fetch_assoc($this->result);
}
}
function setResult($q = NULL)
{
if($q == NULL)
{
$q = $this->query;
}
if($q == NULL)
{
return FALSE;
}
else
{
$this->result = @mysql_query($q);
}
}
SCRIPT:
//runQuery -- Should run the query and store the Result and Query
$q = "SELECT * FROM make ORDER BY make";
$db->runQuery($q);
//fetchAssoc -- return current row of result set and move pointer ahead
foreach($db->fetchAssoc() as $key => $value)
{
echo $value." has a foreign key of: ".$key."<br />";
}
//Also tried
while($row = fetchAssoc())
{
echo $value." has a foreign key of: ".$key."<br />";
}
私も試みます。while($行= fetchAssoc())が、それはあなたが 'setResult'方式を投稿することができ超えると – Stewie
上で同じ結果を返しますか? –
関数setResult($ Q = NULL) \t {\t \t場合($ Q == NULL) \t \t { \t \t \t $ Q =の$ this - >クエリ。 \t \t \t} \t \t($ Q == NULL) \t \t { \t \t \t戻りFALSEであれば、他\t \t \t} \t \t \t \t { \t \t \tの$ this - >結果= @mysql_query($のQ); \t \t \t \t – Stewie