簡體   English   中英

為什么此php代碼無法從mysql數據庫中獲取第一行?

[英]Why is this php code not fetching the first row from the mysql database?

似乎此php代碼可獲取數據庫中的所有行,但不會獲取第一行。 如果您調用數據庫中的過程(請參見下面的過程),則它將按預期顯示所有行。 該數據庫有四列,在代碼中,它使用echo來從第二行打印出數據,這是因為第一條記錄沒有顯示,所以我認為它沒有被獲取。 那么,可能是什么問題呢?

    //this is the broken part of my code
    $statement = $conn->prepare('call GetImage()');

        $statement->execute();

      while($row = $statement->fetch()){

    $dest_slash = str_replace('-', '/', $row[2]);
    $dest_slash_backslash = str_replace(';','\\', $dest_slash);
    $replace_root = str_replace($_SERVER['DOCUMENT_ROOT'],'',$dest_slash_backslash);
    $row[2] = $replace_root;

    $images_paths_with_num[] = array($image_count,$row[2]);
    $image_count++;
    echo $row[1];
  }

這是我正在使用的存儲過程:

    CREATE DEFINER=`0901972749`@`%` PROCEDURE `GetImage`()
begin
    select imageID,imageName,imagePath,imageText
    from Images limit 500;
end

請參閱此過程(與問題相同):

   CREATE DEFINER=`0901972749`@`%` PROCEDURE `GetImage`()
begin
    select imageID,imageName,imagePath,imageText
    from Images limit 500;
end

由於事情未按正確的順序顯示,因此需要在此情況下向其添加一個order by語句“ order by imageID”。 為了確保數據以正確的順序顯示,我們需要使用order by子句。 但是,存儲過程可能不是正確的解決方案。 對於那個很抱歉 :)

像這樣:

CREATE DEFINER=`0901972749`@`%` PROCEDURE `GetImage`()
begin
    select imageID,imageName,imagePath,imageText
    from Images limit 500 order by imageID;
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM