PHP - 查询不太正确

时间:2017-01-17 17:28:49

标签: php mysql

我需要从此列中选择时间。

Picture 1

列类型是日期时间。

我现在有这个代码而且它的工作正常但不是我想要的:

$qcreatetime = mysql_query("SELECT create_time FROM ".SQL_HP_DB.".account WHERE id='".$_SESSION['user_id']."'");

while ($rowcreatetime = mysql_fetch_array($qcreatetime))

{$createtime = $rowcreatetime["create_time"];

echo $createtime;}

我用打印的echo得到了这个结果:

SELECT create_time FROM account_3.account WHERE id ='2'

我仍然收到此错误:

Picture 2

2 个答案:

答案 0 :(得分:0)

这是正确的语法:

def get_relationships(model):
    fields = list(model._meta.get_fields())

    m2m_fields = {}
    #Getting m2m relationships first
    for i, field in enumerate(fields):
        print(field)
        if field.is_relation:
            if field.many_to_many:
                fields.pop(i)
                try:
                    #If its a forward field, we want the relationship instead
                    if not hasattr(field,'field'):
                        field = field.remote_field
                except AttributeError:
                    pass
                if hasattr(field,'through'):
                    through = field.through
                    #In case of recursive relationships, there will be duplicates so we don't need to do it again
                    if m2m_fields.get(through._meta.model.__name__):
                        continue
                    m2m_fields[through._meta.model.__name__] = {}
                    m2m = m2m_fields[through._meta.model.__name__]
                    #Finding the models which participate in the through table and the direction
                    m2m['owner'] = {'model' : field.model.__name__}
                    m2m['related'] = {'model' : field.related_model.__name__}
                    recursive = False
                    #Checking recursivity, will use this later
                    #Finding field names for the foreignkeys of the through table
                    for through_field in through._meta.get_fields():
                        if not (through_field.related_model is None):
                            if m2m['owner']['model'] == through_field.related_model.__name__ and not m2m['owner'].get('field'):
                                m2m['owner']['field'] = through_field.name
                            elif m2m['related']['model'] == through_field.related_model.__name__ and not m2m['related'].get('field'):
                                m2m['related']['field'] = through_field.name
                        elif not through_field.primary_key:
                            if not m2m.get('rel_fields'):
                                m2m['rel_fields'] = []
                            m2m['rel_fields'].append(through_field.name)
    #Now removing the through tables from the fields list, because they appear as a regular ManyToOne relationship otherwise
    for through_table in m2m_fields.keys():
        name = through_table
        for i, field in enumerate(fields):
            if field.many_to_one:
                if field.__name__ and field.related_model:
                    if field.related_model.__name__ == name:
                        fields.pop(i)
    #Todo : OneToOne and ManyToOne relationships

    return m2m_fields


for key,value in get_relationships(Pessoa).items():
    print(key, " = ", value)

在会话变量之前和之后,您有一个单引号和双引号。那些都是错的。

答案 1 :(得分:0)

问题出现在另一个问题中,所以现在一切都按照我的意愿运作。