Thursday, 21 June 2018

MySQL Incorrect datetime value: '0000-00-00 00:00:00' Problem rectification Error 1292 (22007) in mysql

Solution for  ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'created' at row 1

(on MySQL 5.7.13).
I kept getting the Incorrect datetime value: '0000-00-00 00:00:00' error.
Strangely, this worked: SELECT * FROM users WHERE created = '0000-00-00 00:00:00'. I have no idea why the former fails and the latter works... maybe a MySQL bug?

At any case, this UPDATE query worked:
UPDATE users SET created = NULL WHERE CAST(created AS CHAR(20)) = '0000-00-00 00:00:00'
All the best !!!

Install phpMyAdmin in Ubuntu 16.04 LTS

phpMyAdmin is available in the default repositories of Ubuntu operating system. Once LAMP stack is installed and ready, install phpMyAdmin as shown below:


sudo apt-get install phpmyadmin


Install phpmyadmin
Install phpmyadmin
During installing, you’ll be asked to choose the web server that should be automatically configured to run phpMyAdmin. In our case, it is Apache webserver.
Choose apache2 and click OK.
sk@ubuntuserver: ~_002
Select Yes and hit ENTER to configure database for phpmyadmin with dbconfig-common.
sk@ubuntuserver: ~_003
Enter a password for phpmyadmin to register with the database server. If left blank, a random password will be generated.
sk@ubuntuserver: ~_004
Re-enter the password to confirm:
sk@ubuntuserver: ~_005
Oops! You might be encountered with the following error message:
An error occurred while installing the database: 

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using 
password: NO) . Your options are: 
* abort - Causes the operation to fail; you will need to downgrade, 
   reinstall, reconfigure this package, or otherwise manually intervene 
   to continue using it. This will usually also impact your ability to 
   install other packages until the installation failure is resolved. 
* retry - Prompts once more with all the configuration questions 
   (including ones you may have missed due to the debconf priority 
   setting) and makes another attempt at performing the operation. 
* retry (skip questions) - Immediately attempts the operation again, 
   skipping all questions. This is normally useful only if you have 
   solved the underlying problem since the time the error occurred.
sk@ubuntuserver: ~_006
To fix this issue, click OK and abort the phpMyAdmin installation.
sk@ubuntuserver: ~_007
Log in to MariaDB or MySQL prompt with root user using command:
mysql -u root -p
Create a new database and database user for phpMyAdmin and grant full permission to the phpmyadmin user.
For the purpose of this tutorial, I am going to create a database called “phpmyadmindb”, and database user “phpmyadminuser” with password “ubuntu”. Please use a strong password which is very hard to guess in the production environment.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE phpmyadmindb;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL ON phpmyadmindb.* TO phpmyadminuser@localhost IDENTIFIED BY 'ubuntu';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> \q
Bye
sk@ubuntuserver: ~_009
Then, edit phpmyadmin/config-db.php file:
sudo nano /etc/phpmyadmin/config-db.php
Replace the database name, database user and its password with the values that you have created earlier.
[...]

$dbuser='phpmyadminuser';
$dbpass='ubuntu';
$basepath='';
$dbname='phpmyadmindb';
$dbserver='localhost';
$dbport='';
$dbtype='mysql';
sk@ubuntuserver: ~_010
Save and close the file.
Next, you must install the following php modules. Otherwise, you will get an error message that says:
The mbstring extension is missing. Please check your PHP configuration.
To install php modules, run:
sudo apt-get install php-mbstring php7.0-mbstring php-gettext
Then, edit Apache webserver config file:
sudo nano /etc/apache2/apache2.conf
Add the following line at the end:
Include /etc/phpmyadmin/apache.conf
sk@ubuntuserver: ~_011
Save and close the file. Restart apache service to take effect the changes.
sudo systemctl restart apache2

Access phpMyAdmin dashboard

Open up the web browser and navigate to http://IP-Address/phpmyadmin.
You should see the following screen. Enter the MariaDB/MySQL ‘root’ user name and its password.
phpMyAdmin - Chromium_012
Congrats! This is how the phpMyAdmin dashboard looks like.
192.168.1.105 - localhost | phpMyAdmin 4.5.4.1deb2ubuntu2 - Chromium_013
From here, you can create, delete, rename, and manage the databases easily.
Source : https://www.ostechnix.com/install-phpmyadmin-with-lamp-stack-on-ubuntu-16-04/

Wednesday, 20 June 2018

To display hyperlinks in cdetailview in yii that is to display uploaded files in yii

<?php $path = Yii::app()->baseUrl."/uploads/"; ?>  // First we have to Declare the path before the attaching the filename in the link this is the key step. 

/* then after we can defile the attribute as follows */
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'lan_no',
array(
'label' => 'Uploaded Image',
'type'=>'raw',
'value' => CHtml::link(CHtml::encode($model->image), $path .$model->image,array("target"=>"_blank"))
),
'man_code',
'vil_code',
'loc_name',
'sur_no',
'tsno',
'blo_name',
'nala_rem',
),
)); ?>

That's it if you want you can remove the target="_blank" option 

To display uploaded files in Cgridview ( in admin view ) in yii

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'works-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'department',
'descofwork',
'typeofwork',
'workstatusrem',
array(
'header' => 'WORK Agreement Copy',         // Header  for the column
'name' => 'workagreement',                           // Name of the database field
'value' => '($data->workagreement === "NIL" ? $data->workagreement :CHtml::link($data->workagreement,Yii::app()->baseUrl."/uploads/".$data->workagreement,array("target"=>"_blank")))',
'type'=>'raw',
),
'place',
'village',
array(
'class'=>'CButtonColumn',
'template'=>$format,
),
),
)); ?>