Home | About | View All Posts

30 May 2016

PDO exception issue YII2 advanced login interface integration - Solved

YII2 Database Exception - yii\db\exception, caused by PDO exception issue tracking and solutions have been written here to help those who are facing exception error in YII2 login interface installation.

We face THREE TYPE of error or problems while working and installing YII2 user or login interface at local xampp or wamp server at windows machine.

TYPE ONE - Database Exception Error
After successful initialization of YII2 installation, just go at login page and type username and password as dummy text and hit login button. You will get “Database Exception error” as screenshot below –
Default login page link in my case -

TYPE TWO - YII2 migrate command not working error i.e error on Migrate command in advanced Yii2 app
Yii provides a set of migration command line tools that allow us to – create, apply, revert, re-apply and show history/status migrations. All these tools are accessible through the command - “ yii migrate”.

In my case it was like below -
G:\wamp\www\yiitest\advanced\yii migrate

You get following error – as screenshot below, if “migrate” command doesnot works.

TYPE THREE – “YII” command not runs and says –“php.exe” is not recognized as an internal or external command, operable program or batch file – error

Type three error is caused due to invalid path setting for “php.exe” in ‘yii.bat’ file. This ‘yii.bat’ file resides at root of the advanced installation folder.

Open or edit the file ‘yii.bat’ in notepad and place your ‘php.exe’ path in the appropriate location.
For this replace the line below -

"%PHP_COMMAND%" == "" set PHP_COMMAND= php.exe
with -
"%PHP_COMMAND%" == "" set PHP_COMMAND=G:\wamp\bin\php\php5.5.12\php.exe

Type one and two errors are caused due to invalid path setting of - mysql socket file. You can view the emply value for “mysql socket file” in the phpinfo display. Just place a test file with phpinfo function to see the empty value. Here it has been shown in the screenshot below with actual value. It should not show “no value” –

If phpinfo shows “no value” for “mysql_default_socket”, you need to place the real value at your server settings file – php.ini and my.ini file.

In my case both file path were -

Please verify the screenshot below to change and place the value for “mysql_default_socket” –

File – my.ini

File – php.ini

Now go at phpmyadmin and create a new user with password.

Edit the privilege for newly added user. In my case user was – yiitest.

Select the database in the list box, for providing the previleges.

Must tick the “Check All” check box value.

Please update the username and password at “main-local.php” file now.
File path – advanced/common/config/main-local.php

Now go at login page and place dummy username and password and see the result. You should not view the “PDO exception” error now.
Instead of “PDO exception” error you would view the following new error with PDO exception error.

The above error indicates that there are no –‘migration’ and ‘user’ tables in the current database. It means database connection is working successfully now.
Now open the command window and run “yii migrate” command. You would see the following successful command output at screenshot below –

Please go at phpmyadmin and check the two newly created tables – migration and user.

It indicates that we can now work on login interface via database. YII2 has inbuilt ability for login and signup, you donot need to recreate it.

Just browse the frontend signup form using url - /advanced/frontend/web/index.php?site/signup

In my case url was -

At this signup page register yourself by filling the signup form then try to login at the url - /advanced/frontend/web/index.php?site/login

In my case login url was -

You will view the post login pages links - about, contact etc. at the top nav bar after successful login.

Enjoy Now!!!

Tags :


Post a Comment