PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php /* function get_records($db, $status = [1,2,3,4], $user_id = false) { $params = $status; $in = str_repeat('?,', count($status) - 1) . '?'; $query = "SELECT id, user_id, url, dr FROM sources WHERE status IN ($in)"; if ($user_id) { $query .= " AND user_id = ?"; $params[] = $user_id; } $stmt = prepared_query($db, $query, $params); return $stmt->get_result()->fetch_all(MYSQLI_ASSOC); } */ $test=array(); $test[]="deneme1"; $test[]="deneme2"; $test[]="deneme3"; $test[]="deneme4"; $test[]="deneme5"; $test1=array(); $test1[]="test1"; $test1[]="test2"; $test1[]="test3"; $test1[]="test4"; $test1[]="test5"; prepared_query(null,"SELECT id, user_id, url, dr FROM sources WHERE status IN (?) and user_id=? and url in (?)",[$test,'duuuuu',$test1]); function prepared_query($mysqli, $sql, $params, $types = "") { $temp_sql=$sql; if (count($params)>0) { // echo "2.-"; $doNeedCallFuncArray=false; $index_mark=1; foreach ($params as $propt => $vall) { //echo "-".$vall; if (is_array($vall) === true) { $pos = strposY($temp_sql, '?', $index_mark); $replace_str1=implode(',',array_fill(0,count(array_unique(array_keys($vall))),'?')); $index_mark+=count(array_unique(array_keys($vall))); $sql = substr_replace($sql, $replace_str1, $pos-1, 1); } else { $index_mark+=1; } } echo $sql ; } /* $types = $types ?: str_repeat("s", count($params)); $stmt = $mysqli->prepare($sql); $stmt->bind_param($types, ...$params); $stmt->execute(); return $stmt; */ } function strposX($haystack, $needle, $number) { preg_match_all("/$needle/", $haystack, $matches, PREG_OFFSET_CAPTURE); return $matches[0][$number-1][1]; } function strposY($haystack, $needle, $n = 0) { $offset = 0; for ($i = 0; $i < $n; $i++) { $pos = strpos($haystack, $needle, $offset); if ($pos !== false) { $offset = $pos + strlen($needle); } else { return false; } } return $offset; }
Show:  
Copy Clear