2013-04-26 1 views
2

200 개 이상의 행을 복사하여 붙여 넣지 않고 MySQL 데이터베이스에 SVG 데이터를 저장하려고합니다. MySQL의 데이터베이스에 다음을 가져올 수있는 방법이 있습니까 :모범 사례 Jvectormap jQuery 파일을 MySql로 가져 오기

"LR": { 
    "path": "M401.37,273.67l-0.32,0.01l-2.48,-1.15l-2.24,-1.89l-2.14,-1.38l-1.47,-1.42l0.44,-0.59l0.05,-0.13l0.12,-0.65l1.07,-1.3l1.08,-1.09l0.52,-0.07l0.43,-0.18l0.84,1.24l-0.15,0.89l0.07,0.25l0.49,0.54l0.22,0.1l0.71,0.01l0.27,-0.16l0.42,-0.83l0.19,0.02l-0.06,0.52l0.23,1.12l-0.5,1.03l0.06,0.35l0.73,0.69l0.14,0.08l0.71,0.15l0.92,0.91l0.06,0.76l-0.17,0.22l-0.06,0.15l-0.17,1.8Z", 
    "name": "Liberia", 
    "continent": "africa" 
}, 

어떤 도움을 크게 감사합니다.

+0

내가 솔루션을 잠시 동안 검색되었지만 아직까지 발견되지 않은, 어떤 독창적 인 솔루션을해야합니까? –

답변

0

이 트릭 :

<?php 

$db =' 
     "BD": { 
      "path": "M652.71,228.85l-0.04,1.38l-0.46,-0.21l-0.42,0.3l0.05,0.65l-0.17,-1.37l-0.48,-1.26l-1.08,-1.6l-0.23,-0.13l-2.31,-0.11l-0.31,0.36l0.21,0.98l-0.6,1.11l-0.8,-0.4l-0.37,0.09l-0.23,0.3l-0.54,-0.21l-0.78,-0.19l-0.38,-2.04l-0.83,-1.89l0.4,-1.5l-0.16,-0.35l-1.24,-0.57l0.36,-0.62l1.5,-0.95l0.02,-0.49l-1.62,-1.26l0.64,-1.31l1.7,1.0l0.12,0.04l0.96,0.11l0.19,1.62l0.25,0.26l2.38,0.37l2.32,-0.04l1.06,0.33l-0.92,1.79l-0.97,0.13l-0.23,0.16l-0.77,1.51l0.05,0.35l1.37,1.37l0.5,-0.14l0.35,-1.46l0.24,-0.0l1.24,3.92Z", 
      "name": "Bangladesh" 
     }, 
     "BE": { 
      "path": "M429.28,143.95l1.76,0.25l0.13,-0.01l2.16,-0.64l1.46,1.34l1.26,0.71l-0.23,1.8l-0.44,0.08l-0.24,0.25l-0.2,1.36l-1.8,-1.22l-0.23,-0.05l-1.14,0.23l-1.62,-1.43l-1.15,-1.31l-0.21,-0.1l-0.95,-0.04l-0.21,-0.68l1.66,-0.54Z", 
      "name": "Belgium" 
     }, 
     "BF": { 
      "path": "M413.48,260.21l-1.22,-0.46l-0.13,-0.02l-1.17,0.1l-0.15,0.06l-0.73,0.53l-0.87,-0.41l-0.39,-0.75l-0.13,-0.13l-0.98,-0.48l-0.14,-1.2l0.63,-0.99l0.05,-0.18l-0.05,-0.73l1.9,-2.01l0.08,-0.14l0.35,-1.65l0.49,-0.44l1.05,0.3l0.21,-0.02l1.05,-0.52l0.13,-0.13l0.3,-0.58l1.87,-1.1l0.11,-0.1l0.43,-0.72l2.23,-1.01l1.21,-0.32l0.51,0.4l0.19,0.06l1.25,-0.01l-0.14,0.89l0.01,0.13l0.34,1.16l0.06,0.11l1.35,1.59l0.07,1.13l0.24,0.28l2.64,0.53l-0.05,1.39l-0.42,0.59l-1.11,0.21l-0.22,0.17l-0.46,0.99l-0.69,0.23l-2.12,-0.05l-1.14,-0.2l-0.19,0.03l-0.72,0.36l-1.07,-0.17l-4.35,0.12l-0.29,0.29l-0.06,1.44l0.25,1.45Z", 
      "name": "Burkina Faso", 
      "continent": "africa" 
     } 
'; 

$dbeach = explode("}", $db); 

print_r($dbeach); 

function get_string($string, $start, $end){ 
$string = " ".$string; 
$pos = strpos($string,$start); 
if ($pos == 0) return ""; 
$pos += strlen($start); 
$len = strpos($string,$end,$pos) - $pos; 
return substr($string,$pos,$len); 
} 


$con=mysqli_connect("host","username","pass","db"); 
// Check connection 
if (mysqli_connect_errno()) 
    { 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 


foreach ($dbeach as $value) { 

    $countrycode = get_string($value, '"', '": {'); 
    $path = get_string($value, '"path": "', '",'); 
    $name = get_string($value, '"name": "', '",'); 
    $continent = get_string($value, '"continent": "', '"'); 

    mysqli_query($con,"INSERT INTO countries (countrycode, path, name, continent) 
    VALUES ('$countrycode', '$path', '$name', '$continent')"); 
} 
mysqli_close($con); 

?>