2016-09-09 65 views
-2

我如何使用SELECT Python中的查詢?如何在Python中使用select查詢?

我只是需要一個很好的示例!

例在PHP中:

$query = $db_connection -> prepare ("SELECT * FROM table WHERE name = :name"); 

    $query -> execute (array (":name" => $name)); 

    $rows = $query -> fetchAll (PDO::FETCH_ASSOC); 

    foreach ($rows as $row) 
    { 
     $id = $row["id"]; 
    } 

    echo $id; 

我需要在Python同樣的功能,其中是輸入!

回答

0

答案:

query = ("""SELECT * FROM table WHERE name = '%s'""" % (name)) 

cursor.execute (query) 

results = cursor.fetchall() 
for row in results: 
id = row[0] 
print (id) 
相關問題