Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function query($mysqli,$sql,$a_params) {
- if (count($a_params)==0) {
- $stmt=($mysqli)->prepare($sql);
- $stmt->execute();
- }
- else {
- $stmt = $mysqli->prepare($sql);
- if($stmt === false) {
- trigger_error('Wrong SQL: ' . $sql . ' Error: ' . ($mysqli)->errno . ' ' . ($mysqli)->error, E_USER_ERROR);
- }
- /* use call_user_func_array, as $stmt->bind_param('s', $param); does not accept params array */
- call_user_func_array(array($stmt, 'bind_param'), refValues($a_params));
- /* Execute statement */
- $stmt->execute();
- }
- $res = $stmt->get_result();
- return $res;
- }
- function refValues($arr)
- {
- if (strnatcmp(phpversion(),'5.3') >= 0) //Reference is required for PHP 5.3+
- {
- $refs = array();
- foreach($arr as $key => $value)
- $refs[$key] = &$arr[$key];
- return $refs;
- }
- return $arr;
- }
- //include $_SERVER['DOCUMENT_ROOT']."/include/config.php";
- $json_array = file_get_contents('https://api.exline.systems/public/v1/regions/origins?country=KZ');
- $php_array = json_decode( $json_array , true );
- if (!is_array($php_array)) die('Json convert error');
- $regions=$php_array['regions'];
- foreach ( $regions as $row) {
- //var_dump($row);
- query($__ссылка_на_mysqli__,
- "INSERT INTO table_json (
- id,
- title,
- cached_path
- zone
- origin
- destination
- cached_parent
- ) VALUES (?,?,?,?,?,?,?)", array(
- "isssiis",
- $row['id'],
- $row['title'],
- $row['cached_path'],
- $row['zone'],
- $row['origin'],
- $row['destination'],
- $row['cached_parent'],
- )
- );
- //$mysql_query = "insert into `table_json` (`".implode( '`,`',$fields). "`) values ('".implode( "','",$values)."')";
- //echo $mysql_query;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement