Saturday, November 7, 2020

PHP / MySQL tables optimization

The php code below optimize all tables in MySQL database.


<?php
echo '< html > < body >';
$servername = "*****";
$username = "*****";
$password = "*****";
$database = "****";

// Create connection
$connection = new mysqli($servername, $username, $password, $database);

if ($connection -> connect_errno) {
  echo "Failed to connect to MySQL: " . $connection -> connect_error;
  exit();
}
echo "Connected successfully
"; $sql = "show tables"; if (!$result = $connection->query($sql)) { die ('There was an error running query[' . $connection->error . ']'); } while ($row = $result->fetch_array()) { $table_name = $row[0]; echo 'Optimizing table: '.$table_name.'...... '; $connection->query("OPTIMIZE TABLE '".$tablename."'"); echo ' ....done
'; } $connection->close(); echo 'Disconnected
'; die("End"); echo '< body > < html >'; ?>

Script execution output on Prestashop 1.6 database will be like:

Connected successfully 
Optimizing table: pequi_access...... ....done 
Optimizing table: pequi_accessory...... ....done 
Optimizing table: pequi_address...... ....done 
Optimizing table: pequi_address_format...... ....done ....... 
Optimizing table: temp_attr...... ....done 
Disconnected
End

Saturday, April 4, 2020

session_start(): Failed to read session data joomla

In this post we will resolve problem that occures ofently:
This problem is due essentially to MySQL connection
1- Verify your SQL connection (Servie is up)
2- Connect with your joomla user to database
   mysql -u your_user -p 
   Enter your password
3- You may have this errror
    ERROR 1524 (HY000): Plugin '*F70658E9BDD2910AC33ACDA164605DFC1DA70A68' is not loaded

4- All right: this proble occures when MySQL password encryption is not supported.
    4.1- Login with root
           
 mysql -u root -p Enter your password;
use mysql;
update user set authentication_string=PASSWORD("your_password") where User='joomla_user';
update user set plugin="mysql_native_password" where User='joomla_user';
flush privileges;
quit;


--> Now refresh your website page and it works

Sometimes we need to restart MySQL for unknown bug, then u can run:
1- mysqladmin.exe -u root -p shutdown
   <Enter your root password>
2-  mysqladmin.exe -u root -p start
   <Enter password>
End go to 4th statement above.

Tested on MySQL 5.7.17 Community Server
             Windows 10 [version 10.0.18362.720]
             Php 7.1.3
             Joomla 3.9.16

Sunday, March 29, 2020

Html CSS background transition using jQuery

Supposing we have to animate body background-image change, this small code can help:

<script>
 
var bgs = ['background-image-1','background-image-2','background-image-3];/*Must be filled with images urls*/
var nbBgImages = 3; /*Must be changed if we have more or less then 3 images*/
</script>
Note:
background-image-1, background-image-2, background-image-1,....,background-image-N must have this form:
url(image-url)

Let's continue javascript and then we'll add a litte css style:
Assuming we are using jQuery we add this script inline or in separate js file:

 
(function($) {
var currentShowingBg = 1;
setInterval(changeBgImage, 7000);
function changeBgImage(){
$("body").css("background-image", bgs[currentShowingBg]);
++currentShowingBg;
if(currentShowingBg >= nbBgImages) currentShowingBg = 0;
}
})(jQuery);


all right now with js
Let's add transitions :
<style>
 
body{

background-repeat:no-repeat;>
background-position:center;
background-color:black !important;
-webkit-transition-property: background-image;
-webkit-transition-duration: 4.0s;
-webkit-transition-timing-function: ease-out;
}

</style>
Now it works ! you can stop here

Let's optimize !
There s a little shity problem with previous code: in case we have big images, latence time spend in images download will affect transitions.

A little trick is to load all images inside the html code but HIDDEN, then knowing that ready function of jquery launched only when DOM is loaded entierly we'll avoid the problem:
Let's add this html:

 
<div style="display:none">
<img src="image1"/>
<img src="image2"/>
<img src="image3"/>

</div>


all right.
See you in j2ee snippets that's better.