Insertion into database failed
P粉314265155
P粉314265155 2022-08-19 21:27:09
0
3
1245

<?php

// pdo: preprocessing

// The essence of preprocessing: the data in the sql statement is dynamically bound

// Dynamic binding: real data is bound only when sql is executed

// Static binding: data is written directly to sql

// 1. Static: select * from staff where id > 10

// 2. Dynamic (preprocessing): select * from staff where id > ?

##// 1. Anonymous parameter index array

namespace pdo_edu;

use PDO;

// Connection

$db = new PDO('mysql:dbname=bittel', 'root', 'root');

// CURD: INSERT

// Anonymous parameters: ?

$sql = 'INSERT `staff` SET `name`= ?,`sex`= ?,`email`= ?;';

// sql statement->sql statement template object->preprocessing object

$stmt = $db->prepare($sql);

/ / Placeholder in sql statement?, bind real data to it

// Index array

$data = ['Yangguo', 0, 'yangguo@qq.com'] ;

//Execute sql

$stmt->execute($data);

// Verification: Print sql preprocessing command

// $stmt->debugDumpParams();

echo 'Added successfully, id = ' . $db->lastInsertId () . '<br>';

QQ图片20220819212656.png

P粉314265155
P粉314265155

reply all(2)
autoload

QQ截图20220819220306.png

This is my field type, you can insert it normally using your code

image.png

  • reply If the ID is equal to 0, the insertion has not been successful. There is no data in the database and the iD value has not changed.
    P粉314265155 author 2022-08-20 07:50:22
autoload

What error was reported?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template