아래처럼 함수를 만들어서 <year>2011</year>같은 경우
select_xml(tablename, \"year\", CONDITION);처럼 해서 2011만 추출하려고 하는데
그냥 putty로
select MID(deion,instr(deion,\'<\'),5) from TABLE; 하면 되는데 위에 함수써서 하면 안되는지 모르겠네요
혹시나 해서 <대신 [로 해서 [year]2011[/year] 이런식으로 하니까 되던데... <를 tag로 인식하는거 같은데 왜 mysql에서 할떄는 되는지...
function select_xml($table_name, $xml, $condition=\'\', $type= \"\", $value_array = \"\")
{
$sql = \"SELECT \".\"MID(deion, INSTR(deion,\'\" .htmlspecialchars(\'<\'.$xml.\'>\'). \"\')+2+\".strlen($xml).\",INSTR(deion,\'\".htmlspecialchars(\'</\'.$xml.\'>\'). \"\')-INSTR(deion,\'\" .htmlspecialchars(\'<\'.$xml.\'>\'). \"\')-2-\".strlen($xml).\") FROM \".$table_name;
if(!empty($condition))
{
$sql.= \" \".$condition;
}
$this->last_query = $sql;
if(!empty($type))
{
$all_query_ok=true;
$stmt = $this->db_link->prepare($sql);
$temp = array();
foreach($value_array as $key => $value)
{
$temp[$key] = &$value_array[$key];
}
call_user_func_array(\'mysqli_stmt_bind_param\', array_merge (array($stmt, $type), $temp))? null : $all_query_ok= false;
$stmt->execute()? null : $all_query_ok= false;
$fields = array();
$out = array();
foreach ($label_array as $key => $value)
{
$fields[$value] = &$out[$value];
}
call_user_func_array(\'mysqli_stmt_bind_result\', array_merge (array($stmt), $fields))? null : $all_query_ok= false;
$d = array();
if(!$all_query_ok)
{
return $d;
}
while($stmt->fetch())
{
$tempArr = array();
foreach ($fields as $key => $value)
{
if(count(explode(\" \",$key)) > 0)
{
$key = end(explode(\" \",$key));
}
$tempArr[$key] = $value;
}
$d[] = $tempArr;
}
$stmt->close();
return $d;
}
else
{
$d = array();
$result = $this->db_link->query($sql);
if(!$result)
{
return $d;
}
while($values = $result->fetch_assoc())
{
$d[] = $values;
}
$result->close();
return $d;
}
}
댓글 0