Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法正确使用Python_Python_Sql_Mariadb_Driver - Fatal编程技术网

无法正确使用Python

无法正确使用Python,python,sql,mariadb,driver,Python,Sql,Mariadb,Driver,我和MariaDB有问题 在Python中使用以下代码时:- print(maria) a= maria.execute("select * from new_table") print(a) 它打印:- <MySQLdb.cursors.Cursor object at 0x000002020CB17BC8> 2 我得到以下信息:- +------+------+ | aval | bval | +------+------+ | 10 | Ok | | 20 |

我和MariaDB有问题

在Python中使用以下代码时:-

print(maria)
a= maria.execute("select * from new_table")
print(a)
它打印:-

<MySQLdb.cursors.Cursor object at 0x000002020CB17BC8>
2
我得到以下信息:-

+------+------+
| aval | bval |
+------+------+
|   10 | Ok   |
|   20 | Kk   |
+------+------+
我已经检查了我在终端和Python程序中使用的是相同的数据库。

所做的就是执行查询。然后,您需要从光标获取数据,例如,您可以使用:

或者,您可以将光标用作迭代器:

maria.execute("select * from new_table")
for row in maria:
    print(row)

这很奇怪,因为当我在sql server上使用a=sql\u server.executeselect*from new\u table时,我会收到一个,但在MariaDB中,我会收到一个!我猜是不同的驱动程序,我只熟悉MySQL/MariaDB一个…根据execute的返回值没有定义。@GeorgRichter感谢这个链接-我只见过MySQL文档。我想如果它们没有定义,那就留给驱动程序编写者了。如果他们指定了一个返回值,以避免出现这样的问题,即一个驱动程序返回光标,而另一个驱动程序似乎返回行数,则会更有帮助。
maria.execute("select * from new_table")
row = maria.fetchone()
while row is not None:
    print(row)
    row = maria.fetchone()
maria.execute("select * from new_table")
for row in maria:
    print(row)