/** * format a array for a insert query string +----------------------------------------- * @param array $data * @param bool $multiple * @return string */ function insert_array($data, $multiple = false, $mukey = '') { if ($multiple || isset($data[0])) { $value = array(); $sql = array(); foreach ($data as $i => $v) { $rs = insert_array($v, false, $i + 1); $value = array_merge($value, $rs['value']); $sql[] = $rs['sql']; } $key = array_keys($data[0]); $key = '(`' . implode('`,`', $key) . '`)'; return array('column' => $key, 'sql' => implode(',', $sql), 'value' => $value); } else { $value = array(); foreach ($data as $k => $v) { if ($v === null) { $data[$k] = 'NULL'; } else { $value[":{$k}{$mukey}"] = $v; $data[$k] = ":{$k}{$mukey}"; } } $key = ''; if ($mukey === '') { $key = array_keys($data); $key = '(`' . implode('`,`', $key) . '`)'; } return array('column' => $key, 'sql' => '(' . implode(',', $data) . ')', 'value' => $value); } }
} else { if (!empty($_POST['url'])) { // Request a url for create a new product. $url = trim($_POST['url']); $pos = strpos($url, '/dp/B'); $len = 4; if ($pos === false) { $pos = strpos($url, '/gp/product/B'); $len = 12; if ($pos === false) { json_return(null, 1, 'URL is wrong.'); } } $pcode = substr($url, $pos + $len, 10); $product = array('code' => $pcode, 'url' => '', 'cover' => 0, 'title' => '', 'star' => '', 'user' => $uid, 'disable' => 0); list($column, $sql, $value) = array_values(insert_array($product)); $rs = $db->prepare("INSERT INTO `a_good` {$column} VALUES {$sql};")->execute($value); if (!$rs) { json_return(null, 1, 'Save failed.'); } $product['id'] = (int) $rs; } } $header = array('Cache-Control: no-cache', 'Connection: keep-alive', 'Pragma: no-cache', 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36'); $cookies = array(); $cookie_file = PT_PATH . 'log/amz_cookie.log'; if (file_exists($cookie_file)) { $cookies = (include $cookie_file); } $_cookie = ''; foreach ($cookies as $k => $v) {