AddHeader("RETS-Version"-6ren">
gpt4 book ai didi

php - PHrets - 使用 PHP 从 rets 创建 mysql 表 - 脚本

转载 作者:行者123 更新时间:2023-11-29 12:13:18 24 4
gpt4 key购买 nike

我在网上找到了这段代码,它将连接到 rets feed 并创建 mysql 表。

<?php 

/* Raw example on how to use phrets to generate the necessary sql code
for mysql tables generation from rets.
Works for me*/

require ('phrets0.6.1.php');


$rets = new phRETS;

$Host = 'http://demo.crt.realtors.org:6103/rets/login';
$Account = 'Joe';
$Password = 'Schmoe';
$User_Agent = 'RETS_class/1.0';
$Rets_Version = 'RETS/1.5' ;



$rets->AddHeader("Accept", "*/*");
$rets->AddHeader("RETS-Version", "$Rets_Version");
$rets->AddHeader("User-Agent", "$User_Agent");
$rets->SetParam("cookie_file", "phrets_cookies.txt");
//$rets->SetParam("debug_mode", TRUE); // ends up in rets_debug.txt


$rets->Connect($Host,$Account,$Password);
$ResourcesInfo1 = $rets->GetMetadataInfo();
$MetadataInfo1 = $rets->GetMetadataTypes();
/*testing4GetTables*/
function GetTables($ResourcesInfo, $MetadataInfo) {
/* Put toghether all the rets info needed for database tables creation
in an array. */
foreach ($MetadataInfo as $key => $value){
$Resource = $value['Resource'];
foreach ($value['Data'] as $key){
$tables[$key['Description']] = array(
'ResourceID' => $Resource,
'Description' => $key['Description'],
'ClassName' => $key['ClassName'] ,
'KeyField' => $ResourcesInfo[$Resource]['KeyField'],
'ClassCount' => $ResourcesInfo[$Resource]['ClassCount']
);
}

}
return $tables;
}

function CreateMysqlTables ($ResourcesInfo, $MetadataInfo, $class){
/*function providing the mysql code needed to create mysqltables.
to be run as the script on the commande line for nicer output*/
$table = GetTables($ResourcesInfo, $MetadataInfo);

foreach ($table as $key => $value){

$TablesAndFields[$value['Description']] = $class-
>GetMetadata($value['ResourceID'],$value['ClassName']);
}

foreach ($TablesAndFields as $key => $value){
$find = array ('/ /', '/-/');
$TableName = preg_replace($find, "_", $key);
echo "\n\r CREATE TABLE IF NOT EXISTS $TableName (\n\r";
foreach ( $value as $key2 => $value2){
echo "`$value2[SystemName]` ";
ConvertTypeToMysql($value2[DataType], $value2[MaximumLength]);
}
echo "`MyNewTablesTimeStamp` timestamp NOT NULL default
CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n\r";
echo " PRIMARY KEY (".$table[$key]['KeyField']."));\n\r";
}
}

function ConvertTypeToMysql($datatype, $datalenght){
/* This function to convert mls datatype and datalenght to mysql.
Change to fit your needs works for me: db2 to mysql (flexmls)*/
switch ($datatype){
case "Character":
if ($datalenght >= 255){
echo "text collate utf8_unicode_ci default NULL, \n\r";

}
elseif (!$datalenght){
echo "$datatype(25) collate utf8_unicode_ci default NULL, \n\r";

}
else {
echo "$datatype($datalenght) collate utf8_unicode_ci default NULL,
\n\r";

}

break;

case "Decimal":

echo "$datatype($datalenght,0) default NULL, \n\r";
break;

case "Int":

echo "$datatype($datalenght) default NULL, \n\r";
break;

case "Long":
/* note:if I put this case after case ("Date" or "Boolean"): it won't
work, Why? is Long a Boolean?'*/
echo "LONGTEXT collate utf8_unicode_ci default NULL, \n\r";
break;

case ("Date" or "Boolean"):

echo "$datatype default NULL, \n\r";
break;


}

}
CreateMysqlTables ($ResourcesInfo1, $MetadataInfo1, $rets);

$rets->Disconnect();

?>

抱歉,代码很长。

我已使用 IDE 通过 FTP 建立了与我的 Wordpress 站点的连接,并在其中加载了 PHrets 文件。

我的最终目标是用 rets feed 中的所有列表填充 mysql 数据库,然后让我的网站以此为基础工作,同时数据库会经常更新,检查更新或新的列表。

如果有人能指出我正确的方向,我将不胜感激。

最佳答案

好吧,在我提供一些建议之前,这是当您想要在 IDX 规则下操作时的简单路径(即这不适用于 VOW)。忘记 RETS 并获取您自己的数据源。也许使用 IDX 提供程序是获取数据的更好方法。看看这两个:IDX Broker http://www.idxbroker.com/mls/florida-keys-mls-flkmlshttp://www.diversesolutions.com/idx-coverage/floridakeysmls-410 。我不确定这是否是您的 MLS,还有很多 IDX 提供商。您应该能够获得与您的 MLS 对话的完整列表,因为 IDX 提供商必须向每个 MLS 注册。

如果您想要或需要自己的 RETS feed 和数据库,这里有一些提示

  • 几年前我使用过 PHRETS 一次——从那时起我就建立了自己的客户端。我不是 PHRETS 的最新版本,但看起来您正在使用一个非常旧的客户端 phrets0.6.1.php 。你应该看看https://github.com/troydavisson/PHRETS和版本 2。
  • 查看其 Wiki 页面以获取更多信息 https://github.com/troydavisson/PHRETS/wiki
  • 如果您想了解有关 RETS 的更多信息,您可以在 RESO(房地产标准组织)及其规范中找到更多信息 http://www.reso.org/specifications 。向您的 MLS 检查他们正在使用什么 RETS 版本。
  • 尽管 RETS 作为标准应该可以帮助您获取数据(因为它是一种传输协议(protocol)),但它没有定义如何使用 Feed 格式化实际数据。 RESO 在 RESO 字典上工作了十多年,该词典应该规范所有 MLS 中的数据,但这仍在进行中,我们永远不知道所有 900 多个 MLS 需要多长时间才能采用此标准。

关于php - PHrets - 使用 PHP 从 rets 创建 mysql 表 - 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30290682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com