Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $today = date("Y-m-d");
- try {
- $dbh = new PDO('mysql:dbname=NAME; host=localhost', 'USER', 'PASSWORD');
- } catch (PDOException $e) {
- die($e->getMessage());
- }
- $sth = $dbh->prepare("INSERT INTO `main` SET
- `tel` = :tel,
- `mail` = :mail,
- `theme_first` = :themef,
- `theme_second` = :themes,
- `dateadd` = :dateadd"
- );
- $sth->execute(array(
- 'tel' => '788888888888',
- 'mail' => 'xxxx@mail.ru',
- 'themef' => 'Автосервис',
- 'themes' => 'Кузовные',
- 'dateadd' => $today
- ));
- $insert_id = $dbh->lastInsertId();
- echo 'insert_id <pre>'; var_dump($insert_id); echo '</pre>';
- // Так работает только с переменными потому что bindParam:
- $tel = '798887776655';
- $b=$pdo->prepare(" INSERT INTO `main` SET tel=:tel");
- $b->bindParam(":tel", $tel);
- $b->execute();
- $LastId = $pdo->lastInsertId();
- // А так будет ошибка
- $b->bindParam(":tel", '798887776655');
- // А так будет работать и со значениями потому что bindValue:
- $b=$pdo->prepare(" INSERT INTO `main` SET tel=:tel");
- $b->bindValue(":tel", '7333344455');
- $b->execute();
- $LastId2 = $pdo->lastInsertId();
Add Comment
Please, Sign In to add comment