I have a table named "orders" in an SQL database:
id date name orderID
========================
1 1502 John ?
2 1502 Jane ?
The "id" is set to AUTO_INCREMENT and the "date" is created when I insert data via my php form:
if ( !empty($_POST)) {
$name = $_POST['name'];
$valid = true;
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO orders (name,date) values(?,CURDATE())";
$q = $pdo->prepare($sql);
$q->execute(array($name));
Database::disconnect();
}
}
I wish that the value for "orderID" is created automatically from the values "id" and "date":
id date name orderID
========================
1 1502 John 15021
2 1502 Jane 15022
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…