- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想在 MySQL 中获取一个数组。有人可以告诉我如何使用 Python 和 MySQLdb 来做到这一点吗?
例如,这是我想用 Python 做的:
<?php
require_once('Config.php');
$q = mysql_query("SELECT * FROM users WHERE firstname = 'namehere'");
$data = mysql_fetch_array($q);
echo $data['lastname'];
?>
谢谢。
最佳答案
在 python 中你有 dictionary=True
,我已经在 python3 中测试过。这将返回与 php 中的关联数组非常相似的目录。例如。
import mysql.connector
cnx = mysql.connector.connect(user='root', password='',host='127.0.0.1',database='test1')
cursor = cnx.cursor(dictionary=True)
sql= ("SELECT * FROM `users` WHERE id>0")
cursor.execute(sql)
results = cursor.fetchall()
print(results)
关于Python 等效于 PHP mysql_fetch_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11565487/
我是初学者,我有一个错误 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
所以我有 3 个数据库表,除了表的名称外,它们在各个方面都是相同的(数据不同)。我这样做是为了可以像这样使用带有开关的一段代码: function disp_bestof($atts) { extr
我有一个数据库,其中包含带有指向其中每一集的链接的行。我正在尝试使用下面的代码来获取一种类型节目的所有链接,并且我成功地做到了这一点。我似乎无法弄清楚的是如何只显示其中一行,而不是让它们全部显示在一行
$n=mysql_num_rows($rs); $i=0; while($n>0) { while(($row=mysql_fetch_a
你好, 我是 php 新手,我在使用 mysql_fetch_array() 时遇到了一些问题。 $sql = "SELECT mandant_kurz FROM pu_mandant ORDER B
我有这样的问题。我写: $id = $wpdb->get_results("SELECT * FROM wp_posts WHERE post_type='video'"); whil
当我尝试 print_r mysql_fetch_array 的 sql 查询时,我得到了这个结果。 Array ( [0] => 1 [id] => 1 [1] => 201
我有以下代码: $mostRecent = mysql_query("SELECT couponID FROM users_coupons WHERE userID = '$userID' ORDER
我真的非常需要以下代码的帮助。我只是不明白为什么它不起作用。 我需要查询一个 MySQL 表,我只需要为特定 ID 返回一行。然而 mysql_fetch_array 只返回该表的第一列 - 我快要沮
我正在使用此代码来显示管理员用户: 1"))){ echo ''.$write['username'].''; } ?> 但是页面一直在加载!有什么问题吗? 最佳答案 这是一个无限循环。您一遍
我不是 PHP 的新手,但我没怎么用过 MySQL,所以我会问问你们这个问题。 我有一个包含一行数据的数据库,其中包含一个日期和两个整数。但是,当我用这个查询数据库时: $query = "SELEC
下面的脚本是在数据库中搜索查询 ( $matric_no ),以便它返回名称(名字,姓氏, 其他名称)和其他学生信息。它工作正常,只要它返回一行,但每当返回两行或更多行时 名称(所有行都相同)的迭代次
如何对从 mysql_fetch_array() 返回的数组执行搜索并用 php 替换?如果我使用 preg_replace()它不会返回匹配项。我缺少什么吗?这是我使用过但没有成功的方法,任何人都可
我遇到了这样一种情况:将 mysql_query() 结果馈送到 mysql_fetch_array() 函数中,该结果被解释为 bool 值而不是结果。 下面的代码使用 Using an SQL r
问题标题说明了一切:我想循环遍历每一行,但我只得到每隔一行。有趣的是,当我使用 mysql_num_rows 时,如下所示,它得到了正确的计数。怎么了? $query = "SELECT * FROM
我试图显示来自 mysql 的值,但它返回任何空页面。连接正常,但无法从 mysql 获取数据。我尝试了类似问题的所有答案。但没有任何帮助。有人能帮帮我吗?这是代码 $con= mysql_
我收到以下错误消息: Notice: Undefined index: timein in time.php on line 42 Notice: Undefined index: timeout i
我有一个 while 循环,其中包含另一个 while 循环。两个循环都迭代不同的 mysql 结果集。问题是,外部 while 循环第二次调用内部 while 循环时,它不会运行。 Mysql_fe
好的,我执行这个 $table = get_personel_table(1); function get_personel_table($id) { global $conn
我在这里彻底崩溃了。我试图从使用 mysql_fetch_array() 的查询中获取结果,但它带来了 from 值。这是一个简单的示例: 这是查询: $query = SELECT COUNT(*)
我是一名优秀的程序员,十分优秀!