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 somewhere ( id INT AUTO_INCREMENT, name VARCHAR(100), PRIMARY KEY (id) ); INSERT INTO somewhere(id, name) VALUES (1, 'Chad'), (4, 'Ned'), (5, 'Dave'), (14, 'Newt'), (18, 'Bill'), (21, 'Norton'), (25, 'Alan');

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

Copy Clear
Copy Format Clear
<?php $columnValuePairs = ['name' => 'Jeff']; $table = 'somewhere'; $stmt = $pdo->prepare( sprintf( "INSERT INTO `$table` (`%s`) VALUES (%s)", implode('`, `', array_keys($columnValuePairs)), implode(',', array_fill(0, count($columnValuePairs), '?')) ) ); $stmt->execute(array_values($columnValuePairs)); var_export($pdo->lastInsertId()); var_export($pdo->query("SELECT * FROM `$table`")->fetchAll(PDO::FETCH_ASSOC));
Copy Clear