<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # MySQLdb 獲取結果 > 原文: [https://thepythonguru.com/fetching-results/](https://thepythonguru.com/fetching-results/) * * * 于 2020 年 1 月 7 日更新 * * * 在上一篇文章中,我們看到了如何使用`execute()`方法執行 sql 查詢。 `execute()`方法返回受影響的行,但不返回結果。 要獲取結果,我們使用游標對象的`fetchall()`方法。 **語法**: `cursor.fetchall()` 成功后,它將返回行的元組,其中每一行都是一個元組。 ```py from __future__ import print_function import MySQLdb as my db = my.connect(host="127.0.0.1", user="root", passwd="", db="world" ) cursor = db.cursor() number_of_rows = cursor.execute("select * from city"); result = cursor.fetchall() print(result) db.close() ``` 上面的代碼將打印城市表中的所有行。 您也可以使用`for`循環遍歷結果。 ```py from __future__ import print_function import MySQLdb as my db = my.connect(host="127.0.0.1", user="root", passwd="", db="world" ) cursor = db.cursor() number_of_rows = cursor.execute("select * from city"); result = cursor.fetchall() for row in result: print(row) db.close() ``` 一些更多的例子。 **示例 1**: ```py from __future__ import print_function import MySQLdb as my db = my.connect(host="127.0.0.1", user="root", passwd="", db="world" ) cursor = db.cursor() id = 10 operation = ">" sql = "select * from city where id {} {}".format(operation, id) number_of_rows = cursor.execute(sql) result = cursor.fetchall() for row in result: print(row[0], row[1]) db.close() ``` **示例 2**: ```py from __future__ import print_function import MySQLdb as my db = my.connect(host="127.0.0.1", user="root", passwd="", db="world" ) cursor = db.cursor() city = "%pur%" sql = "select * from city where name like '{}'".format(city) number_of_rows = cursor.execute(sql) result = cursor.fetchall() for row in result: print(row[0], row[1]) db.close() ``` 在下一篇文章中,我們討論如何[將行插入數據庫](/inserting-rows/)中。 * * * * * *
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看