Yii 查找查询结果 - 无表结构 [英] Yii find query result - without table structure

查看:24
本文介绍了Yii 查找查询结果 - 无表结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对模型使用以下查询

$criteria = new CDbCriteria; 
$criteria->condition='brand_id=3';
$model=Models::model()->find($criteria);

它给出了如下表结构和关系表结构的结果

it gives result with Table structure and relational table structure like below

Models Object ( [_md:CActiveRecord:private] => CActiveRecordMetaData Object ( [tableSchema] => CMysqlTableSchema Object ( [schemaName] => [name] => models [rawName] => `models` [primaryKey] => model_id [sequenceName] => [foreignKeys] => Array ( [brand_id] => Array ( [0]
=> brands [1] => brand_id ) ) [columns] => Array ( [model_id] => CMysqlColumnSchema Object ( [name] => model_id [rawName] => `model_id` [allowNull] => [dbType] => int(11) [type] => integer [defaultValue] => [size] => 11 [precision] => 11 [scale] => [isPrimaryKey] => 1 [isForeignKey] => [autoIncrement] => 1 [_e:CComponent:private] => [_m:CComponent:private] => ) [model_name] => CMysqlColumnSchema Object ( [name] => model_name [rawName] => `model_name` [allowNull] => [dbType] => varchar(255) [type] => string [defaultValue] => [size] => 255 [precision] => 255 [scale] => [isPrimaryKey] => [isForeignKey] => [autoIncrement] => [_e:CComponent:private] => [_m:CComponent:private]
=> ) [brand_id] => CMysqlColumnSchema Object ( [name] => brand_id [rawName] => `brand_id` [allowNull] => [dbType] => int(11) [type] => integer [defaultValue] => [size] => 11 [precision] => 11 [scale] => [isPrimaryKey] => [isForeignKey] => 1 [autoIncrement] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [_e:CComponent:private] => [_m:CComponent:private] => ) [columns] => Array ( [model_id] => CMysqlColumnSchema Object ( [name] => model_id [rawName] => `model_id` [allowNull] => [dbType] => int(11) [type] => integer [defaultValue] => [size] => 11 [precision] => 11 [scale] => [isPrimaryKey] => 1 [isForeignKey] => [autoIncrement] => 1 [_e:CComponent:private] => [_m:CComponent:private] => ) [model_name]
=> CMysqlColumnSchema Object ( [name] => model_name [rawName] => `model_name` [allowNull] => [dbType] => varchar(255) [type] => string [defaultValue] => [size] => 255 [precision] => 255 [scale] => [isPrimaryKey] => [isForeignKey] => [autoIncrement] => [_e:CComponent:private] => [_m:CComponent:private] => ) [brand_id] => CMysqlColumnSchema Object ( [name] => brand_id [rawName] => `brand_id` [allowNull] => [dbType] => int(11) [type] => integer [defaultValue] => [size] => 11 [precision] => 11 [scale] => [isPrimaryKey] => [isForeignKey] => 1 [autoIncrement] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [relations] => Array ( [brand] => CBelongsToRelation Object ( [joinType] => LEFT OUTER JOIN [on] => [alias] => [with] => Array ( ) [together] => [scopes] => [name] => brand [className] => Brands [foreignKey] => brand_id [select] => * [condition] => [params] => Array ( ) [group] => [join] => [having] => [order] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [attributeDefaults] => Array ( ) [_model:CActiveRecordMetaData:private] => Models Object ( [_md:CActiveRecord:private] => CActiveRecordMetaData Object
*RECURSION* [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => Array ( ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => [_e:CComponent:private] => [_m:CComponent:private] => ) ) [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => Array ( [model_id] => 3 [model_name] => NANO [brand_id] => 3 ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => 3 [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => update [_e:CComponent:private] => [_m:CComponent:private] => )

如何仅在 yii 查询中获取表数据

How can i get table data only in yii queries

推荐答案

返回的数据是一个 CActiveRecord 对象.返回的数据有这样的复杂性是正常的.如果您只想获取 DB 值,您应该使用 Yii 的 DAO 功能或查询生成器功能!

The returned data is a CActiveRecord object. It's normal to have such complexity in the returned data. If you want to obtain just the DB values, you should use the DAO feature or the Query Builder feature from Yii!

使用查询生成器的示例:

Example using Query Builder:

$model = Yii::app()->db->createCommand()
    ->select('*')
    ->from('your_table t')
    ->where('brand_id=:id', array(':id'=>3))
    ->queryRow();

使用 DAO 的示例:

Example using DAO:

$connection=Yii::app()->db;
$command=$connection->createCommand('SELECT * FROM your_table WHERE id =:id');
$command->bindParam(":id", 3, PDO::PARAM_INT);
$row=$command->queryRow();

这篇关于Yii 查找查询结果 - 无表结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆