This code neither prompts an error nor can I see the result. Please tell me where the error is. Thank you!
邯郸易住宋至刚
邯郸易住宋至刚 2019-08-01 20:48:35
0
7
1684

<?php
/**
Use PDO to complete the database connection
*/
require 'pdo_conf.php';
try
{
$pdo = new PDO($dsn,$userName ,$password);
//echo '<h3>Connection successful</h3>';
$sql = "INSERT student (id,name,course,grade) VALUES ('11',Wu Song ','mysql','80')";
$num = $pdo->exec($sql);
$insertId = $pdo->lastInsertId();
if($ NUM & GT; 0) {
PRINT 'successfully added'. $ NUM. 'Receives, and the new primary key ID was'. $ insertid;
}
} cach (pdoexception $ e) {
die('Operation failed'.$e->getMessage());
}

邯郸易住宋至刚
邯郸易住宋至刚

//m.sbmmt.com/course/1073.html

reply all(4)
王先生

ID is self-increasing and automatically generated. It can't be inserted.

V

Add echo 'Insertion successful!' directly below $num = $pdo->exec($sq);

Please let me know if it is incorrect! Thanks!

  • reply Hello, after inserting echo 'insert successfully', run, the page displays "insert successfully", but no data is inserted into the data table.
    邯郸易住宋至刚 author 2019-08-21 10:20:27
邯郸易住宋至刚

The database connection is successful, no problem

Peter-Zhu

I don’t see your connection code, not sure if your connection is successful? You can print out the SQL statement and see if it is correct? Or directly execute it in the SQL command line to locate the error?

  • reply Hello, the sql statement is placed in the data table and executed using SQL commands, and the data can be successfully inserted.
    邯郸易住宋至刚 author 2019-08-21 10:23:34
  • reply Use mysqli_connect method to connect to the database. The parameters are the same. The connection can be normal and the data can be inserted normally.
    邯郸易住宋至刚 author 2019-08-21 14:40:24
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template