Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE sources ( id int, user_id int, status varchar(100), url varchar(100) ); INSERT INTO sources VALUES (1, 1,'deneme1','test1'), (2, 1,'deneme1','test1'), (3, 1,'deneme1','test1'), (4, 2,'deneme2','test2'), (5, 2,'deneme2','test2'), (6, 2,'deneme1','test3'), (7, 3,'deneme1','test3'), (8, 3,'deneme3','test3'), (9, 3,'deneme3','test4'), (10, 4,'deneme1','test4'), (11, 4,'deneme4','test5'), (12, 4,'deneme4','test6') ;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $test=array(); $test[]="deneme1"; $test[]="deneme2"; $test[]="deneme3"; $test[]="deneme4"; $test[]="deneme5"; $test1=array(); $test1[]="test1"; $test1[]="test2"; $test1[]="test3"; $test1[]="test4"; $test1[]="test5"; $query="select * from sources where url='test2'"; $result=mysqli_query($mysqli,$query); $row=mysqli_fetch_array($result); echo $row["status"]; /* $tms=create_in_select($mysqli,"SELECT id, user_id, url FROM sources WHERE status IN (?) and user_id=? and url in (?)",[$test,1,$test1]); $result=$tms->fetch_all(MYSQLI_ASSOC); foreach ($result as $row) { printf("%s \n", $row["url"]); } */ function create_in_select($conn, $sql, $param_list, $type_list = "") { return create_in_query($conn, $sql, $param_list, $type_list)->get_result(); } function create_in_query($conn, $sql, $param_list, $type_list = "") { $scount=0; $index_mark=1; $paramq=array(); if (count($param_list)>0) { foreach ($param_list as $propt => $vall) { if (is_array($vall) === true) { $pos = strposY($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); $paramq=array_merge($paramq,$vall); } else { $index_mark+=1; $paramq[]=$vall; } } $scount = $index_mark-1; $types=str_repeat('s',$scount); $paramq=array_merge([$types],$paramq); $refs=[]; foreach($paramq as $key=>$value) { $refs[$key]=&$paramq[$key]; } $stmtnew = $conn->prepare($sql); call_user_func_array([$stmtnew,'bind_param'],$refs); $stmtnew->execute(); return $stmtnew; } else { $stmtnew = $conn->prepare($sql); $stmtnew->execute(); return $stmtnew; } } 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; }
Copy Clear