search

Home  >  Q&A  >  body text

This code neither prompts an error nor can I see the result. Please tell me where the error is. Thank you!

<?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());
}

邯郸易住宋至刚邯郸易住宋至刚1983 days ago1695

reply all(7)I'll reply

  • 王先生

    王先生2019-12-12 11:12:59

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

    reply
    0
  • 王林

    王林2019-08-20 17:33:56

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

    Please let me know if it is incorrect! Thanks!

    reply
    0
  • 邯郸易住宋至刚

    Hello, after inserting echo 'insert successfully', run, the page displays "insert successfully", but no data is inserted into the data table.

    邯郸易住宋至刚 · 2019-08-21 10:20:27
  • 邯郸易住宋至刚

    邯郸易住宋至刚2019-08-02 18:51:46

    The database connection is successful, no problem

    reply
    0
  • 天蓬老师

    天蓬老师2019-08-02 16:45:42

    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
    0
  • 邯郸易住宋至刚

    Hello, the sql statement is placed in the data table and executed using SQL commands, and the data can be successfully inserted.

    邯郸易住宋至刚 · 2019-08-21 10:23:34
    邯郸易住宋至刚

    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.

    邯郸易住宋至刚 · 2019-08-21 14:40:24
  • Cancelreply