We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Why does not it run properly my phalconphp framework model??

I have suceessfuly install a invo sample application in my computer. But sadly It DOES NOT runs properly as the Use model can not find any data although there is really a in my MySQL database.

As a debug way,I record all sql statement executed in MySQL.

/usr/local/mysql/bin/mysqld, Version: 5.5.28-log (Source distribution). started with: Tcp port: 3306 Unix socket: /tmp/mysql.sock Time Id Command Argument 130414 9:05:33 1 Connect [email protected] on invo 1 Prepare SELECT IF(COUNT()>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='users' 1 Execute SELECT IF(COUNT()>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='users' 1 Close stmt
1 Prepare DESCRIBE users 1 Execute DESCRIBE users 1 Close stmt
1 Prepare SELECT users.id, users.username, users.password, users.name, users.email, users.created_at, users.active FROM users WHERE users.email = '[email protected]' AND users.password = 'c0bd96dc7ea4ec56741a4e07f6ce98012814d853' AND users.active = 'Y' LIMIT 1 1 Execute SELECT users.id, users.username, users.password, users.name, users.email, users.created_at, users.active FROM users WHERE users.email = '[email protected]' AND users.password = 'c0bd96dc7ea4ec56741a4e07f6ce98012814d853' AND users.active = 'Y' LIMIT 1 1 Close stmt
1 Prepare SELECT users.id, users.username, users.password, users.name, users.email, users.created_at, users.active FROM users WHERE users.username = '[email protected]' AND users.password = 'c0bd96dc7ea4ec56741a4e07f6ce98012814d853' AND users.active = 'Y' LIMIT 1 1 Execute SELECT users.id, users.username, users.password, users.name, users.email, users.created_at, users.active FROM users WHERE users.username = '[email protected]' AND users.password = 'c0bd96dc7ea4ec56741a4e07f6ce98012814d853' AND users.active = 'Y' LIMIT 1 1 Close stmt
1 Quit
130414 9:06:17 2 Connect [email protected] on 2 Query select @@version_comment limit 1 /usr/local/mysql/bin/mysqld, Version: 5.5.28-log (Source distribution). started with: Tcp port: 3306 Unix socket: /tmp/mysql.sock Time Id Command Argument 130414 9:05:33 1 Connect [email protected] on invo 1 Prepare SELECT IF(COUNT()>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='users' 1 Execute SELECT IF(COUNT()>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='users' 1 Close stmt

============================================

When I visut the https://www.invo.com/session/index(my virtual host) and click the Login button,there is always a banner with "Wrong email/password"..

I find the following statement always return false. $user = Users::findFirst("email='$email' AND password='$password' AND active='Y'");

What is the matter? Is there anyone can help me?? Thank you!!



98.9k

When you execute "SELECT users.id, users.username, users.password, users.name, users.email, users.created_at, users.active FROM users WHERE users.username = '[email protected]' AND users.password = 'c0bd96dc7ea4ec56741a4e07f6ce98012814d853' AND users.active = 'Y' LIMIT 1" in the MySQL console it returns records?

Yes. It does return records in the MySQL console.

As a alternative,it will do the right result when I replace the findFirst with find function.

I am very wonderful about the situation.



98.9k

I don't think Phalcon has a bug here, we have several unit-tests for findFirst, also Phalcon relies on PDO that is more than tested, without mention all the applications running that use findFirst.

There is a live version of INVO running here: https://invo.phalcon.io/

The unit tests:

https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L122 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L126 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L130 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L133 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L139 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L140 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L145 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L151 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L152 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L157 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L158 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L163 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L164 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L169 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L170 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsTest.php#L175 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsSerializeTest.php#L68 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsBehaviorsTest.php#L82 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsDynamicOperationsTest.php#L95 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsDynamicOperationsTest.php#L116 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsEventsTest.php#L126 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsEventsTest.php#L171 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsForeignKeysTest.php#L137 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsForeignKeysTest.php#L152 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsForeignKeysTest.php#L203 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsForeignKeysTest.php#L218 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsRelationsTest.php#L122 https://github.com/phalcon/cphalcon/blob/master/unit-tests/ModelsRelationsTest.php#L155

You can see the tests passing here in 3 different PHP versions: https://travis-ci.org/phalcon/cphalcon

If you find out a test to reproduce the problem please submit it to Github. Thanks