如何使用yii从phpmyadmin数据库中检索数据

时间:2022-10-23 15:38:35

Good day .. I am having a problem here to retrieve data from certain column in db using yii framework.. I am a complete newbie to yii, but still managing,

美好的一天..我在这里有一个问题,使用yii框架从db中的某些列检索数据..我是yii的完全新手,但仍在管理,

I read lot of posts, forums and YouTube but none are working for me to get data from db as I want it, any help is much appreciated!

我阅读了很多帖子,论坛和YouTube,但没有一个能帮我从db获取数据,我非常感谢任何帮助!

When it comes to authenticating users, its perfect. But when normally trying to retrieve other data than user authentication. I keep getting Error 500 Trying to get property of non-object and stuff.

在验证用户时,它是完美的。但通常尝试检索除用户身份验证之外的其他数据。我一直在收到错误500试图获取非对象和东西的属性。

So using the authentication method in SiteControler, I took advantage in the $model .. and re used it for my purpose:

因此,使用SiteControler中的身份验证方法,我利用了$ model ..并将其用于我的目的:

 $user = $model->username;

here username is perfectly giving me the value of username logged in.

这里的用户名完美地给了我登录用户名的值。

But when I try to point from username to check another column in the same row called "UserAuth". It doesn't work!

但是,当我尝试从用户名指向检查名为“UserAuth”的同一行中的另一列时。它不起作用!

I think logically, it should be like this:

我认为逻辑上应该是这样的:

 $model->username->UserAuth;

Am I right? even when I add $this->UserAuth its still the same!!

我对吗?即使我添加$ this-> UserAuth它仍然是相同的!!

The column I want to check is called "UserAuth" in my table called "logins".. So matching the username, was successful, but the same method I used didn't work for checking other column. Hope I gave a clear pic here.

我要检查的列在我的表中称为“UserAuth”,称为“登录”。所以匹配用户名,是成功的,但我使用的相同方法不能用于检查其他列。希望我在这里给出了清晰的图片。

I am using yii 1 not 2, if that help (don't know the difference through)

我正在使用yii 1而不是2,如果有帮助(不知道差异通过)

Again to point that, I am new to web development era .. I used to do basic java SE .. but web seems different!

再说一点,我是Web开发时代的新手。我曾经做过基本的java SE ..但是web似乎不同了!

1 个解决方案

#1


0  

You tried

$model->username->UserAuth;

and

$this->UserAuth

But what you need to do is:

但你需要做的是:

$model->UserAuth;

The $model represents a row in the database. Each column is accessed as a separate property.

$ model表示数据库中的一行。每列都作为单独的属性访问。

$model->username;
$model->UserAuth;
$model->anotherColumn;
$model->yetAnotherColumn;

This, of course, assumes that $model is an object whose class extends CActiveRecord. Without seeing more of your code, I can't be sure that it is or not.

当然,这假设$ model是一个对象,其类扩展了CActiveRecord。没有看到更多的代码,我无法确定它是否存在。

#1


0  

You tried

$model->username->UserAuth;

and

$this->UserAuth

But what you need to do is:

但你需要做的是:

$model->UserAuth;

The $model represents a row in the database. Each column is accessed as a separate property.

$ model表示数据库中的一行。每列都作为单独的属性访问。

$model->username;
$model->UserAuth;
$model->anotherColumn;
$model->yetAnotherColumn;

This, of course, assumes that $model is an object whose class extends CActiveRecord. Without seeing more of your code, I can't be sure that it is or not.

当然,这假设$ model是一个对象,其类扩展了CActiveRecord。没有看到更多的代码,我无法确定它是否存在。