<script><br>
function del(_id) {<br>
if (confirm("Confirm deletion"))<br>
{<br>
window.location.href="index.php?conn_id="+_id; //Refresh this page<br>
}<br>
}<br>
</script>
if(@$_GET['conn_id']!=""){
$dbms='mysql'; //Database type. For developers, if they use different databases, they only need to change this and don’t need to remember so many functions
$host='localhost'; //Database host name
$dbName='db_database19'; //Database used
$user='root'; //Database connection username
$pass='root'; //Corresponding password
$dsn="$dbms:host=$host;dbname=$dbName";
try {
$pdo = new PDO($dsn, $user, $pass); //Initializing a PDO object means creating a database connection object $pdo
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$query="delete from tb_pdo_mysql where Id=:id";
$result=$pdo->prepare($query); //Prepared statement
$result->bindParam(':id',$_GET['conn_id']); //Bind updated data
$result->execute();
} catch (PDOException $e) {
echo 'PDO Exception Caught.';
echo 'Error with the database:
';
echo 'SQL Query: '.$query;
echo '
';<br>
echo "Error: " . $e->getMessage(). "<br/>";<br>
echo "Code: " . $e->getCode(). "<br/>";<br>
echo "File: " . $e->getFile(). "<br/>";<br>
echo "Line: " . $e->getLine(). "<br/>";<br>
echo "Trace: " . $e->getTraceAsString(). "<br/>";<br>
echo '
';
}
}
?>
This code should be placed at the beginning of the body part of the html page, or at worst, before the query record code.
http://www.bkjia.com/PHPjc/904792.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904792.htmlTechArticlephp combines with js to implement click on the hyperlink to perform the delete confirmation operation. First, connect to the database and query the database data: The code is as follows: ?php $dbms='mysql'; //Database type, for developers,...