PHP combined with JS implementation Click on the hyperlink to perform a delete confirmation operation
First, link the database, query the database data:
The code is as follows:
$dbms = ' MySQL '; Database type, for developers, use different databases, just change this, don't remember so many functions
$host = ' localhost '; Database host Name
$dbName = ' db_database19 '; The database used
$user = ' root '; Database connection user Name
$pass = ' root '; The corresponding password
$DSN = "$dbms: host= $host;d bname= $dbName";
try {
$pdo = new PDO ($DSN, $user, $pass); Initializes a PDO object, which is the creation of a database connection object $pdo
$query = "SELECT * from Tb_pdo_mysql"; Defining SQL statements
$result = $pdo->prepare ($query); Preparing query statements
$result->execute (); Executes a query statement and returns a result set
while ($res = $result->fetch (PDO::FETCH_ASSOC)) {//while loops out the query result set and sets the result set as the associated index
?>
) "> Delete
}
} catch (Pdoexception $e) {
Die ("error!:". $e->getmessage (). "
");
}
?>
Call a JavaScript method at hyperlink Delete, passing the record Id,js method is:
The code is as follows:
To delete a database record code:
The code is as follows:
if (@$_get[' conn_id ']!= "") {
$dbms = ' MySQL '; Database type, for developers, use different databases, just change this, don't remember so many functions
$host = ' localhost '; Database host Name
$dbName = ' db_database19 '; The database used
$user = ' root '; Database connection user Name
$pass = ' root '; The corresponding password
$DSN = "$dbms: host= $host;d bname= $dbName";
try {
$pdo = new PDO ($DSN, $user, $pass); Initializes a PDO object, which is the creation of 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); Pre-prepared statements
$result->bindparam (': Id ', $_get[' conn_id '); Binding the updated data
$result->execute ();
} catch (Pdoexception $e) {
Echo ' PDO Exception caught. ';
Echo ' Error with the database:
';
Echo ' SQL Query: '. $query;
Echo '
';
echo "Error:". $e->getmessage (). "
";
echo "Code:". $e->getcode (). "
";
echo "File:". $e->getfile (). "
";
echo "line:". $e->getline (). "
";
echo "Trace:". $e->gettraceasstring (). "
";
Echo '
';
}
}
?>
This code is placed at the very beginning of the body portion of the HTML page and, at worst, before the query record code.
http://www.bkjia.com/PHPjc/904792.html www.bkjia.com true http://www.bkjia.com/PHPjc/904792.html techarticle PHP with JS implementation Click the hyperlink to perform a delete confirmation operation first link the database, query database data: Code as follows:? php $dbms = ' mysql ';//database type, for developers, ...