search

Home  >  Q&A  >  body text

How to test whether PDO calling method is successful

When using PDO, the database connection is normal, but when running this code, the page displays neither results nor errors. Is it because PDO on my side cannot call its method?

<?php
/**
PDO connection database
*/

include 'pdo_conf.php';

$dsn = "{$dbType}:host ={$host};dbName={$userName}";
try{
$pdo = new PDO($dsn,$userName,$password);
// echo '<h3>Connect Success</h3>';
$sql = "UPDATE `student` SET `name` = 'Qin Mingyi' WHERE `student`.`id` = 14;)";
$num = $ pdo->exec($sql);
$insertId = $pdo->lastInsertId();
if($num > 0){
print 'Successfully added'.$num. 'Record, the latest added record ID is'.$insertId;
}
}catch (PDOException $e){
die('Operation failed'.$e->getMessage());
}include 'pdo_conf.php';

$dsn = "{$dbType}:host={$host};dbName={$userName}";
try{
$pdo = new PDO($dsn,$userName,$password);
// echo '<h3>Connection successful</h3>';
$sql = "UPDATE `student` SET `name` = 'Qin Mingyi' WHERE `student`.`id` = 14;)";
$num = $pdo->exec($sql);
$insertId = $pdo->lastInsertId() ;
if($num > 0){
print ''.$num.' records were added successfully, the latest added record ID is '.$insertId;
}
}catch ( PDOException $e){
die('Operation failed'.$e->getMessage());
}

邯郸易住宋至刚邯郸易住宋至刚1941 days ago1570

reply all(2)I'll reply

  • 邯郸易住宋至刚

    邯郸易住宋至刚2019-08-09 16:01:54

    But the problem is that the data was not added successfully.

    reply
    0
  • 在路上...

    在路上...2019-08-09 15:51:57

    If there is no indication, the connection is successful

    reply
    0
  • Cancelreply