Use pdo in mysql to insert data {code ...} the database connection is successfully inserted, but two records will be inserted again after each execution. Another point is how to modify PDOException $ erro. {code ...} after the database connection fails, I want to directly prompt & quot; error & quot;. No need to display it...
Use pdo to insert data in mysql
Try {$ pdo = new PDO ($ dsn, $ user, $ pwd); $ SQL = "INSERT INTO ID (name, time) VALUES ('1', NOW ()) "; $ pdo-> exec ($ SQL);} catch (PDOException $ erro) {echo 'error ';}
The database connection is inserted successfully.
However, after each execution, two records are inserted repeatedly.
Another point is how to modify PDOException $ erro.
} Catch (PDOException $ erro) {echo 'error ';}
I want to directly prompt "error" after the database connection fails, so that nothing else needs to be displayed.
Reply content:
Use pdo to insert data in mysql
Try {$ pdo = new PDO ($ dsn, $ user, $ pwd); $ SQL = "INSERT INTO ID (name, time) VALUES ('1', NOW ()) "; $ pdo-> exec ($ SQL);} catch (PDOException $ erro) {echo 'error ';}
The database connection is inserted successfully.
However, after each execution, two records are inserted repeatedly.
Another point is how to modify PDOException $ erro.
} Catch (PDOException $ erro) {echo 'error ';}
I want to directly prompt "error" after the database connection fails, so that nothing else needs to be displayed.