PHP:MySQL数据库没有返回任何行?

时间:2014-01-10 19:28:19

标签: php python mysql

使用InnoDB引擎从MySql数据库检索行时遇到问题。首先,我准备了大约50个随机字母输入,每个字母输入为几千字节:

inputs <- generate(50, 2048)

然后,对于输入集合中的每个项目,我尝试发布到表单处理程序:

def send_over(item):
    try:
        payload = {'variable': item}
        r = requests.post("http://localhost/handler.php", data=payload, timeout=1.000)    
        if not r:
            print("warning: could not post")
            print("\t", item)
            print()
            return False
    except requests.exceptions.Timeout:
        print("Timeout. Could not post")
        print("\t", item)
        print()
        return False

    return True

发布后,我立即尝试使用

查询插入的最后一行

def check(cnc,item):

# "cnc" is a tuple that contains a connection (cnx) and cursor object
# This is from the Python/connector module.

cnx, cursor = cnc

if not cnx or not cursor:
    print("Problem connecting to database")
    return False

# get last row
query = ("select * from table order by primary_key desc")

# compare database entry with posted data    

cursor.execute(query)

for (primary_key, what) in cursor:
    if what != item:
        print("FAIL: data mismatch")
        return False

return True  

但查询时不返回任何行。为什么会发生这种情况?表单处理程序使用PDO对象和预准备语句。有没有办法(在PHP中)确保每个INSERT都提交到数据库?这是我唯一的猜测。

0 个答案:

没有答案