PHPize Online / SQLize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
create table tbl1 ( id int, val varchar(64) ); insert into tbl1 values (1, 'Test1'); select exists(select * from tbl1 where val = 'Test1');
Copy
Copy Format Clear
<?php function uniquedoesexist($dbHandle, $tablename, $fieldname, $value) { $sql = 'SELECT * FROM `'.$tablename.'` WHERE `'.$fieldname.'` = ? LIMIT 1;'; $stmt = mysqli_prepare($dbHandle, $sql); mysqli_stmt_bind_param($stmt, 's',$value); mysqli_stmt_execute($stmt); mysqli_stmt_store_result($stmt); $found = mysqli_stmt_num_rows($stmt); echo "SqlResult for $value: " . $found . PHP_EOL; return $found; } uniquedoesexist($mysqli, 'tbl1', 'val', 'Test1'); uniquedoesexist($mysqli, 'tbl1', 'val', 'Test11');
Show:  
Copy