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 `test` (`testcol` varchar(20)); INSERT INTO `test` (`testcol`) VALUES ('O\'Neill'), ('Smith'); SELECT * FROM `test`;

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

Copy Clear
Copy Format Clear
<?php $query = "SELECT * FROM `test` WHERE `testcol` = ?"; $var = "O'Neill"; if ( $stmt = mysqli_prepare( $mysqli, $query ) ) { // bind the parameters to the query $bind = mysqli_stmt_bind_param($stmt, "s", $var ); 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']; } } }
Copy Clear