if(isset($_POST['update']))
{
$rets_login_url = $Fetch['rets_url'];
$rets_username = $Fetch['rets_user'];
$rets_password = $Fetch['rets_pass'];
require_once("../include/phrets.php");
$rets = new phRETS;

$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);
$search = $rets->SearchQuery("Property","ResidentialProperty","(Status=A)",
array( "Count" => 1, "Format" => "COMPACT", "Limit" => "1000", "Offset" => "2")
);

$ins = $upd = 0;
while ($listing = $rets->FetchRow($search))
{
extract($listing);
        $photos = $rets->GetObject("Property", "Photo", $listing['Ml_num']);
        $tot_image = 0;
            foreach ($photos as $photo)
            {
            $listing = $photo['Content-ID'];
            $number = $photo['Object-ID'];
                if ($photo['Success'] == true)
                {
                file_put_contents("../../retsimages/image_{$listing}_{$number}.jpg", $photo['Data']);
                }
                else
                {

                echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";

                }

            $tot_image++;

            }

$sql = "SELECT * FROM ".RETS." WHERE `mls` = '$Ml_num'";

$run = mysql_query($sql);

$num = mysql_num_rows($run);

    if($num == "")

    {


 $sql = "INSERT INTO ".RETS." (`id`, `status`, `address`, `description`, `bath`, `bed`, `street`, `country`, `extra`, `Municipality`, `zip`, `mls`, `broker`, `sale_lease`, `lot_price`, `build_year`, `sqft`,`tot_image`,`acres`,`addl_mo_fee`,`addr`,`a_c`,`all_inc`,`yr_built`,`apt_num`,`area`,`area_code`,`tv`,`ass_year`,`bsmt1_out`,`bsmt2_out`,`br`,`br_plus`,`cable`,`cac_inc`,`central_vac`,`comel_inc`,`community`,`community_code`,`cross_st`,`disp_addr`,`drive`,`elevator`,`constr1_out`,`constr2_out`,`den_fr`,`farm_agri`,`fpl_num`,`comp_pts`,`furnished`,`gar_spaces`,`gar_type`,`heat_inc`,`fuel`,`heating`,`hydro_inc`,`idx_dt`,`num_kit`,`kit_plus`,`laundry`,`laundry_lev`,`legal_desc`,`level1`,`level10`,`level11`,`level12`,`level2`,`level3`,`level4`,`level5`,`level6`,`level7`,`level8`,`level9`,`lp_dol`,`depth`,`front_ft`,`irreg`,`lotsz_code`,`mmap_page`,`mmap_col`,`mmap_row`,`municipality_district`,`municipality_code`,`oth_struc1_out`,`oth_struc2_out`,`outof_area`,`park_chgs`,`prkg_inc`,`park_spcs`,`parcel_id`,`pix_updt`,`pool`,`pvt_ent`,`prop_feat1_out`,`prop_feat2_out`,`prop_feat3_out`,`prop_feat4_out`,`prop_feat5_out`,`prop_feat6_out`,`ad_text`,`retirement`,`rm1_out`,`rm1_dc1_out`,`rm1_dc2_out`,`rm1_dc3_out`,`rm1_len`,`rm1_wth`,`rm10_out`,`rm10_dc1_out`,`rm10_dc2_out`,`rm10_dc3_out`,`rm10_len`,`rm10_wth`,`rm11_out`,`rm11_dc1_out`,`rm11_dc2_out`,`rm11_dc3_out`,`rm11_len`,`rm11_wth`,`rm12_out`,`rm12_dc1_out`,`rm12_dc2_out`,`rm12_dc3_out`,`rm12_len`,`rm12_wth`,`rm2_out`,`rm2_dc1_out`,`rm2_dc2_out`,`rm2_dc3_out`,`rm2_len`,`rm2_wth`,`rm3_out`,`rm3_dc1_out`,`rm3_dc2_out`,`rm3_dc3_out`,`rm3_len`,`rm3_wth`,`rm4_out`,`rm4_dc1_out`,`rm4_dc2_out`,`rm4_dc3_out`,`rm4_len`,`rm4_wth`,`rm5_out`,`rm5_dc1_out`,`rm5_dc2_out`,`rm5_dc3_out`,`rm5_len`,`rm5_wth`,`rm6_out`,`rm6_dc1_out`,`rm6_dc2_out`,`rm6_dc3_out`,`rm6_len`,`rm6_wth`,`rm7_out`,`rm7_dc1_out`,`rm7_dc2_out`,`rm7_dc3_out`,`rm7_len`,`rm7_wth`,`rm8_out`,`rm8_dc1_out`,`rm8_dc2_out`,`rm8_dc3_out`,`rm8_len`,`rm8_wth`,`rm9_out`,`rm9_dc1_out`,`rm9_dc2_out`,`rm9_dc3_out`,`rm9_len`,`rm9_wth`,`rms`,`rooms_plus`,`s_r`,`vend_pis`,`sewer`,`spec_des1_out`,`spec_des2_out`,`spec_des3_out`,`spec_des4_out`,`spec_des5_out`,`spec_des6_out`,`st_num`,`st_sfx`,`st_dir`,`st`,`style`,`yr`,`taxes`,`type_own_srch`,`type_own1_out`,`uffi`,`timestamp_sql`,`util_cable`,`gas`,`elec`,`util_tel`,`bath_tot`,`wcloset_t1`,`wcloset_t1lvl`,`wcloset_t2`,`wcloset_p2`,`wcloset_t2lvl`,`wcloset_t3`,`wcloset_p3`,`wcloset_t3lvl`,`wcloset_t4`,`wcloset_p4`,`wcloset_t4lvl`,`wcloset_t5`,`wcloset_p5`,`wcloset_t5lvl`,`water`,`water_inc`,`wtr_suptyp`,`waterfront`,`zoning`)


  VALUES (NULL, 'Active', '$Addr', '$Ad_text', '$Bath_tot', '$Br', '$St', '$County', '$Extras', '$Municipality', '$Zip', '$Ml_num', '$Rltr', '$S_r', '$Lp_dol', '$Yr_built', '$Sqft','$tot_image','$Acres','$Addl_mo_fee','$Addr','$Area','$Area_code','$All_inc','$Yr_built','$Apt_num','$Area','$Area_code','$Tv','$Ass_year','$Bsmt1_out','$Bsmt2_out','$Br','$Br_plus','$Cable','$Cac_inc','$Central_vac','$Comel_inc','$Community','$Community_code','$Cross_st','$Disp_addr','$Drive','$Elevator','$Constr1_out','$Constr2_out','$Den_fr','$Farm_agri','$Fpl_num','$Comp_pts','$Furnished','$Gar_spaces','$Gar_type','$Heat_inc','$Fuel','$Heating','$Hydro_inc','$Idx_dt','$Num_kit','$Kit_plus','$Laundry','$Laundry_lev','$Legal_desc','$Level1','$Level10','$Level11','$Level12','$Level2','$Level3','$Level4','$Level5','$Level6','$Level7','$Level8','$Level9','$Lp_dol','$Depth','$Front_ft','$Irreg','$Lotsz_code','$Mmap_page','$Mmap_col','$Mmap_row','$Municipality_district','$Municipality_code','$Oth_struc1_out','$Oth_struc2_out','$Outof_area','$Park_chgs','$Prkg_inc','$Park_spcs','$Parcel_id','$Pix_updt','$Pool','$Pvt_ent','$Prop_feat1_out','$Prop_feat2_out','$Prop_feat3_out','$Prop_feat4_out','$Prop_feat5_out','$Prop_feat6_out','$Ad_text','$Retirement','$Rm1_out','$Rm1_dc1_out','$Rm1_dc2_out','$Rm1_dc3_out','$Rm1_len','$Rm1_wth','$Rm10_out','$Rm10_dc1_out','$Rm10_dc2_out','$Rm10_dc3_out','$Rm10_len','$Rm10_wth','$Rm11_out','$Rm11_dc1_out','$Rm11_dc2_out','$Rm11_dc3_out','$Rm11_len','$Rm11_wth','$Rm12_out','$Rm12_dc1_out','$Rm12_dc2_out','$Rm12_dc3_out','$Rm12_len','$Rm12_wth','$Rm2_out','$Rm2_dc1_out','$Rm2_dc2_out','$Rm2_dc3_out','$Rm2_len','$Rm2_wth','$Rm3_out','$Rm3_dc1_out','$Rm3_dc2_out','$Rm3_dc3_out','$Rm3_len','$Rm3_wth','$Rm4_out','$Rm4_dc1_out','$Rm4_dc2_out','$Rm4_dc3_out','$Rm4_len','$Rm4_wth','$Rm5_out','$Rm5_dc1_out','$Rm5_dc2_out','$Rm5_dc3_out','$Rm5_len','$Rm5_wth','$Rm6_out','$Rm6_dc1_out','$Rm6_dc2_out','$Rm6_dc3_out','$Rm6_len','$Rm6_wth','$Rm7_out','$Rm7_dc1_out','$Rm7_dc2_out','$Rm7_dc3_out','$Rm7_len','$Rm7_wth','$Rm8_out','$Rm8_dc1_out','$Rm8_dc2_out','$Rm8_dc3_out','$Rm8_len','$Rm8_wth','$Rm9_out','$Rm9_dc1_out','$Rm9_dc2_out','$Rm9_dc3_out','$Rm9_len','$Rm9_wth','$Rms','$Rooms_plus','$S_r','$Vend_pis','$Sewer','$Spec_des1_out','$Spec_des2_out','$Spec_des3_out','$Spec_des4_out','$Spec_des5_out','$Spec_des6_out','$St_num','$St_sfx','$St_dir','$St','$Style','$Yr','$Taxes','$Type_own_srch','$Type_own1_out','$Uffi','$Timestamp_sql','$Util_cable','$Gas','$Elec','$Util_tel','$Bath_tot','$Wcloset_t1','$Wcloset_t1lvl','$Wcloset_t2','$Wcloset_p2','$Wcloset_t2lvl','$Wcloset_t3','$Wcloset_p3','$Wcloset_t3lvl','$Wcloset_t4','$Wcloset_p4','$Wcloset_t4lvl','$Wcloset_t5','$Wcloset_p5','$Water','$Water_inc','$Wtr_suptyp','$Waterfront','$Zoning')";

    $ins++;

    }

    else

    {


    $sql = "UPDATE ".RETS." SET `address` = '$Addr', `description` = '$Ad_text', `bath` = '$Bath_tot', `bed` = '$Br', `street` = '$St', `country` = '$County', `extra` = '$Extras', `Municipality` = '$Municipality', `zip` = '$Zip', `mls` = '$Ml_num', `broker` = '$Rltr', `sale_lease` = '$S_r', `lot_price` = '$Lp_dol', `build_year` = '$Yr_built', `sqft` = '$Sqft', `tot_image` = '$tot_image' WHERE `mls` = '$Ml_num'";

    $upd++;

    }

mysql_query($sql) or die(mysql_error());


这是我从RETS服务器获取和插入Prosperity的代码,它具有200多个字段,并且可能有3000多个记录要获取,因此从本地运行此查询时,它不会插入到我的表中,我知道查询和RETS连接没有错误,如何使循环尽可能长?直到插入所有记录?

最佳答案

您的代码不完整,或者确实是错误的。请尝试以下操作:

if(isset($_POST['update']))
{
    $rets_login_url = $Fetch['rets_url'];
    $rets_username = $Fetch['rets_user'];
    $rets_password = $Fetch['rets_pass'];
    require_once("../include/phrets.php");
    $rets = new phRETS;

    $connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);

    // check for errors
    if ($connect) {
        echo "  + Connected<br>\n";
    } else {
        echo "  + Not connected:<br>\n";
        print_r($rets->Error());
        exit;
    }

    $search = $rets->SearchQuery("Property","ResidentialProperty","(Status=A)",
        array( "Count" => 1, "Format" => "COMPACT", "Limit" => "1000", "Offset" => "2")
    );

    if ($rets->NumRows() > 0) {

        $ins = $upd = 0;
        while ($listing = $rets->FetchRow($search)) {
            extract($listing);

            $photos = $rets->GetObject("Property", "Photo", $listing['Ml_num']);
            $tot_image = 0;
            foreach ($photos as $photo) {
                $listingid = $photo['Content-ID']; // don't redefine $listing!
                $number = $photo['Object-ID'];
                if ($photo['Success'] == true) {
                    file_put_contents("../../retsimages/image_{$listingid}_{$number}.jpg", $photo['Data']);
                } else {
                    echo "({$listing}-{$number}): {$photo['ReplyCode']} = {$photo['ReplyText']}\n";
                }
                $tot_image++;
            }

            // not needed if you do an INSERT ON DUPLICATE KEY UPDATE
            $sql = "SELECT * FROM ".RETS." WHERE `mls` = '$Ml_num'";
            $run = mysql_query($sql);
            $num = mysql_num_rows($run);
            // not needed
            if ($num == "") {
                $sql = "INSERT INTO ".RETS." (`id`, `status`, `address`, `description`, `bath`, `bed`, `street`, `country`, `extra`, `Municipality`, `zip`, `mls`, `broker`, `sale_lease`, `lot_price`, `build_year`, `sqft`,`tot_image`,`acres`,`addl_mo_fee`,`addr`,`a_c`,`all_inc`,`yr_built`,`apt_num`,`area`,`area_code`,`tv`,`ass_year`,`bsmt1_out`,`bsmt2_out`,`br`,`br_plus`,`cable`,`cac_inc`,`central_vac`,`comel_inc`,`community`,`community_code`,`cross_st`,`disp_addr`,`drive`,`elevator`,`constr1_out`,`constr2_out`,`den_fr`,`farm_agri`,`fpl_num`,`comp_pts`,`furnished`,`gar_spaces`,`gar_type`,`heat_inc`,`fuel`,`heating`,`hydro_inc`,`idx_dt`,`num_kit`,`kit_plus`,`laundry`,`laundry_lev`,`legal_desc`,`level1`,`level10`,`level11`,`level12`,`level2`,`level3`,`level4`,`level5`,`level6`,`level7`,`level8`,`level9`,`lp_dol`,`depth`,`front_ft`,`irreg`,`lotsz_code`,`mmap_page`,`mmap_col`,`mmap_row`,`municipality_district`,`municipality_code`,`oth_struc1_out`,`oth_struc2_out`,`outof_area`,`park_chgs`,`prkg_inc`,`park_spcs`,`parcel_id`,`pix_updt`,`pool`,`pvt_ent`,`prop_feat1_out`,`prop_feat2_out`,`prop_feat3_out`,`prop_feat4_out`,`prop_feat5_out`,`prop_feat6_out`,`ad_text`,`retirement`,`rm1_out`,`rm1_dc1_out`,`rm1_dc2_out`,`rm1_dc3_out`,`rm1_len`,`rm1_wth`,`rm10_out`,`rm10_dc1_out`,`rm10_dc2_out`,`rm10_dc3_out`,`rm10_len`,`rm10_wth`,`rm11_out`,`rm11_dc1_out`,`rm11_dc2_out`,`rm11_dc3_out`,`rm11_len`,`rm11_wth`,`rm12_out`,`rm12_dc1_out`,`rm12_dc2_out`,`rm12_dc3_out`,`rm12_len`,`rm12_wth`,`rm2_out`,`rm2_dc1_out`,`rm2_dc2_out`,`rm2_dc3_out`,`rm2_len`,`rm2_wth`,`rm3_out`,`rm3_dc1_out`,`rm3_dc2_out`,`rm3_dc3_out`,`rm3_len`,`rm3_wth`,`rm4_out`,`rm4_dc1_out`,`rm4_dc2_out`,`rm4_dc3_out`,`rm4_len`,`rm4_wth`,`rm5_out`,`rm5_dc1_out`,`rm5_dc2_out`,`rm5_dc3_out`,`rm5_len`,`rm5_wth`,`rm6_out`,`rm6_dc1_out`,`rm6_dc2_out`,`rm6_dc3_out`,`rm6_len`,`rm6_wth`,`rm7_out`,`rm7_dc1_out`,`rm7_dc2_out`,`rm7_dc3_out`,`rm7_len`,`rm7_wth`,`rm8_out`,`rm8_dc1_out`,`rm8_dc2_out`,`rm8_dc3_out`,`rm8_len`,`rm8_wth`,`rm9_out`,`rm9_dc1_out`,`rm9_dc2_out`,`rm9_dc3_out`,`rm9_len`,`rm9_wth`,`rms`,`rooms_plus`,`s_r`,`vend_pis`,`sewer`,`spec_des1_out`,`spec_des2_out`,`spec_des3_out`,`spec_des4_out`,`spec_des5_out`,`spec_des6_out`,`st_num`,`st_sfx`,`st_dir`,`st`,`style`,`yr`,`taxes`,`type_own_srch`,`type_own1_out`,`uffi`,`timestamp_sql`,`util_cable`,`gas`,`elec`,`util_tel`,`bath_tot`,`wcloset_t1`,`wcloset_t1lvl`,`wcloset_t2`,`wcloset_p2`,`wcloset_t2lvl`,`wcloset_t3`,`wcloset_p3`,`wcloset_t3lvl`,`wcloset_t4`,`wcloset_p4`,`wcloset_t4lvl`,`wcloset_t5`,`wcloset_p5`,`wcloset_t5lvl`,`water`,`water_inc`,`wtr_suptyp`,`waterfront`,`zoning`)
                        VALUES (NULL, 'Active', '$Addr', '$Ad_text', '$Bath_tot', '$Br', '$St', '$County', '$Extras', '$Municipality', '$Zip', '$Ml_num', '$Rltr', '$S_r', '$Lp_dol', '$Yr_built', '$Sqft','$tot_image','$Acres','$Addl_mo_fee','$Addr','$Area','$Area_code','$All_inc','$Yr_built','$Apt_num','$Area','$Area_code','$Tv','$Ass_year','$Bsmt1_out','$Bsmt2_out','$Br','$Br_plus','$Cable','$Cac_inc','$Central_vac','$Comel_inc','$Community','$Community_code','$Cross_st','$Disp_addr','$Drive','$Elevator','$Constr1_out','$Constr2_out','$Den_fr','$Farm_agri','$Fpl_num','$Comp_pts','$Furnished','$Gar_spaces','$Gar_type','$Heat_inc','$Fuel','$Heating','$Hydro_inc','$Idx_dt','$Num_kit','$Kit_plus','$Laundry','$Laundry_lev','$Legal_desc','$Level1','$Level10','$Level11','$Level12','$Level2','$Level3','$Level4','$Level5','$Level6','$Level7','$Level8','$Level9','$Lp_dol','$Depth','$Front_ft','$Irreg','$Lotsz_code','$Mmap_page','$Mmap_col','$Mmap_row','$Municipality_district','$Municipality_code','$Oth_struc1_out','$Oth_struc2_out','$Outof_area','$Park_chgs','$Prkg_inc','$Park_spcs','$Parcel_id','$Pix_updt','$Pool','$Pvt_ent','$Prop_feat1_out','$Prop_feat2_out','$Prop_feat3_out','$Prop_feat4_out','$Prop_feat5_out','$Prop_feat6_out','$Ad_text','$Retirement','$Rm1_out','$Rm1_dc1_out','$Rm1_dc2_out','$Rm1_dc3_out','$Rm1_len','$Rm1_wth','$Rm10_out','$Rm10_dc1_out','$Rm10_dc2_out','$Rm10_dc3_out','$Rm10_len','$Rm10_wth','$Rm11_out','$Rm11_dc1_out','$Rm11_dc2_out','$Rm11_dc3_out','$Rm11_len','$Rm11_wth','$Rm12_out','$Rm12_dc1_out','$Rm12_dc2_out','$Rm12_dc3_out','$Rm12_len','$Rm12_wth','$Rm2_out','$Rm2_dc1_out','$Rm2_dc2_out','$Rm2_dc3_out','$Rm2_len','$Rm2_wth','$Rm3_out','$Rm3_dc1_out','$Rm3_dc2_out','$Rm3_dc3_out','$Rm3_len','$Rm3_wth','$Rm4_out','$Rm4_dc1_out','$Rm4_dc2_out','$Rm4_dc3_out','$Rm4_len','$Rm4_wth','$Rm5_out','$Rm5_dc1_out','$Rm5_dc2_out','$Rm5_dc3_out','$Rm5_len','$Rm5_wth','$Rm6_out','$Rm6_dc1_out','$Rm6_dc2_out','$Rm6_dc3_out','$Rm6_len','$Rm6_wth','$Rm7_out','$Rm7_dc1_out','$Rm7_dc2_out','$Rm7_dc3_out','$Rm7_len','$Rm7_wth','$Rm8_out','$Rm8_dc1_out','$Rm8_dc2_out','$Rm8_dc3_out','$Rm8_len','$Rm8_wth','$Rm9_out','$Rm9_dc1_out','$Rm9_dc2_out','$Rm9_dc3_out','$Rm9_len','$Rm9_wth','$Rms','$Rooms_plus','$S_r','$Vend_pis','$Sewer','$Spec_des1_out','$Spec_des2_out','$Spec_des3_out','$Spec_des4_out','$Spec_des5_out','$Spec_des6_out','$St_num','$St_sfx','$St_dir','$St','$Style','$Yr','$Taxes','$Type_own_srch','$Type_own1_out','$Uffi','$Timestamp_sql','$Util_cable','$Gas','$Elec','$Util_tel','$Bath_tot','$Wcloset_t1','$Wcloset_t1lvl','$Wcloset_t2','$Wcloset_p2','$Wcloset_t2lvl','$Wcloset_t3','$Wcloset_p3','$Wcloset_t3lvl','$Wcloset_t4','$Wcloset_p4','$Wcloset_t4lvl','$Wcloset_t5','$Wcloset_p5','$Water','$Water_inc','$Wtr_suptyp','$Waterfront','$Zoning')";
                $ins++;
            } else {
                $sql = "UPDATE ".RETS." SET `address` = '$Addr', `description` = '$Ad_text', `bath` = '$Bath_tot', `bed` = '$Br', `street` = '$St', `country` = '$County', `extra` = '$Extras', `Municipality` = '$Municipality', `zip` = '$Zip', `mls` = '$Ml_num', `broker` = '$Rltr', `sale_lease` = '$S_r', `lot_price` = '$Lp_dol', `build_year` = '$Yr_built', `sqft` = '$Sqft', `tot_image` = '$tot_image' WHERE `mls` = '$Ml_num'";
                $upd++;
            }

            mysql_query($sql) or die(mysql_error());

        } // end while loop

    } // end of $rets->NumRows() check

} // end of $_POST['update'] check


我还会考虑使用INSERT ON DUPLICATE KEY UPDATE而不是根据系统中是否存在该属性尝试编写两个不同的sql查询。

关于php - 只要长时间执行php Rets?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14682353/

10-13 00:40