PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE `test` (`testcol` varchar(20)); INSERT INTO `test` (`testcol`) VALUES ('O\'Neill'), ('Smith'); SELECT * FROM `test`;
Copy Clear
Copy Format Clear
<?php $query = "SELECT * FROM `test` WHERE `testcol` = ?"; $foo = "O'Neill"; if ( $stmt = mysqli_prepare( $mysqli, $query ) ) { // bind the parameters to the query $bind = mysqli_stmt_bind_param($stmt, "s", $foo ); if ( $bind === false ) { $response['error'] = 'Bind: ' . mysqli_error( $conn ); } else { // execute the query if ( mysqli_stmt_execute( $stmt ) === false ) { $response['error'] = 'Execute: ' . mysqli_stmt_error( $stmt ); } else { $result = $stmt->get_result(); $row = $result->fetch_assoc(); echo $row['testcol']; } } }
Show:  
Copy Clear