How using select Query in Python?
<p>How can i use a <strong>SELECT</strong> Query in Python ?</p>

<p><em>I just need a very sample example !</em></p>

<p>Example in PHP :</p>

<pre><code>$query = $db_connection -&gt; prepare ("SELECT * FROM table WHERE name = :name");

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

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

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

    echo $id;
</code></pre>

<p>I need same function in Python where <em>name</em> is an input !</p>

<p>The Answer :</p>

<pre><code>query = ("""SELECT * FROM table WHERE name = '%s'""" % (name))

cursor.execute (query)

results = cursor.fetchall()
for row in results:
id = row[0]
print (id)
</code></pre>

python select