php db new PDO mysql host localhost dbname test root stm db- prepare S

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<?php
$db = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$stm = $db->prepare("SELECT COUNT(id) as count FROM tbl");
$stm->execute();
$lastid = $stm->fetch(PDO::FETCH_OBJ)->count;
$sth = $db->prepare("INSERT INTO tbl(login) VALUES(?)");
$sth->execute(array($lastid + 1));