PHPize Online / SQLize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
CREATE TABLE IF NOT EXISTS `post` ( `id_d` int NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, PRIMARY KEY (`id_d`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Copy
Copy Format Clear
<?php //масив данных $input = [ 1 => 'name', 2 => 'Dale', 3 => 'Conan' ]; //запрос и подготовка $query = "INSERT INTO post (id_d, name) VALUES (:id_d, :name)"; $query = $pdo->prepare($query); //данные сунуть в бд foreach ($input as $key => $name) { $query->execute([':id_d'=> $key,':name'=> $name]); } //проверка $query = "SELECT * FROM post"; $query = $pdo->prepare($query); $query->execute(); $response = $query->fetchAll(PDO::FETCH_ASSOC); print_r($response);
Show:  
Copy