PHP combined with JS implementation click the hyperlink to perform delete confirmation operation _php Tutorial

Source: Internet
Author: User
Tags dsn

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, ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.