微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何删除表中的多行?使用单一代码,无需两次在里面输入 execute 和 conditions

如何解决如何删除表中的多行?使用单一代码,无需两次在里面输入 execute 和 conditions

<?PHP

    date_default_timezone_set('Asia/Kolkata');

    require './Libraries/PHPMailer5/PHPMailerAutoload.PHP';
    $mail = new PHPMailer;

    $mail->isSMTP();

    // Enable SMTP debugging
    // 0 = off (for production use)
    // 1 = client messages
    // 2 = client and server messages
    $mail->SMTPDebug = 2;

    $mail->Debugoutput = 'html';

    $mail->Host = 'localhost';
    $mail->Port = 587;

    $mail->SMTPSecure = 'tls';

    $mail->SMTPAuth = true;
    $mail->Username = "yourWebmailUsermail";
    $mail->Password = "yourWebmailPassword";

    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,'verify_peer_name' => false,'allow_self_signed' => true
        )
    );

    $mail->setFrom('formEmailAddress','First Last');

    $mail->addAddress('toEmailAddress','John Doe');

    $mail->Subject = 'PHPMailer GMail SMTP test';

    $mail->msgHTML("<h1>Hi Test Mail</h1>");
    $mail->AltBody = 'This is a plain-text message body';

    if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!";
    }
?>

cursor.execute("""DELETE FROM Fruits WHERE name='blackBerry'""") cursor.execute("""DELETE FROM Fruits WHERE price='150.00'""")

import sqlite3
conn = sqlite3.connect('example.db') # connectiong to database or creating new if table does 
not exist
cursor = conn.cursor() # allows python to use sql commands

cursor.execute('''CREATE TABLE IF NOT EXISTS Fruits( #creating table
code TEXT PRIMARY KEY,# text data-type,primary key -constraint
name TEXT,price FLOAT);
''')
conn.commit() # saves all changes made
fruit_list = [('1','blackBerry',300.00),('2','raspBerry',250.00),('3','bananas',150.00),('4','strawBerry',200.00)] #list of tuples
cursor.executemany('INSERT INTO Fruits VALUES(?,?,?)',fruit_list) # inserting data into table

解决方法

您可以将 WHERE 子句中的所有条件与逻辑运算符 OR 组合在一个语句中:

DELETE 
FROM Fruits 
WHERE name='blackberry' OR price='150.00'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。