PHP MySQL PDO Insert Record
From w3cyberlearnings
Contents |
PHP PDO Insert Use Query
Use query to insert a new record.
Syntax PDO Insert
$sql = 'INSERT INTO user_infor (id, first_name, last_name, email) VALUES (null,"bob","lema","[email protected]")'; $sq = $db->query($sql);
Example 1
<?php $dns = 'mysql:host=localhost;dbname=w3cyberlearning'; $user = 'user2000'; $pass = 'password2000'; $db = new PDO($dns, $user, $pass); $sql = 'INSERT INTO user_infor (id, first_name, last_name, email) VALUES (null,"bob","lema","[email protected]")'; $sq = $db->query($sql); if ($sq) { echo 'Inserted: ' . $db->lastInsertId(); } ?>
Output
Insert: 1