PHP time() and Mysql now() fucntion

The time () function is a built-in function in PHP . time() returns the current time measured in the number of seconds since the Unix Epoch. The number of seconds can be converted to the current date using date () function in PHP.

<?php
$t=time();
echo($t . "<br>");
echo(date("Y-m-d",$t));
?>

Output

1624962270
2021-06-29

The MySQL NOW() function returns the current date and time in the configured time zone as a string or a number in the 'YYYY-MM-DD HH:MM:DD'  format. The returned type of the NOW() function depends on the context where it is used. For example, in the following statement, the NOW() function returns the current date and time as a string.

select now();

output

PHP time() and Mysql now() fucntion













MySQL Thread Cache Size

 It's advisable to set thread_cache_size so that most new connections use threads from the cache rather than newly created threads. This saves some thread-creation overhead, though normally does not create a significant performance improvement.

To Set the Thread Cache Size Use Below Step

mysql> set global thread_cache_size = 16;

Query OK, 0 rows affected (0.00 sec)


or for a persistent change, edit my.cnf

thread_cache_size       = 16


Have a look at the variables:

mysql> show variables;

+--------------------------------------------------------+--------

| Variable_name                                          | Value

| thread_cache_size                                      | 16

Mysql : how to find the line number of error?

Depending how large the .sql file, you could use a program like notepad2 and open the it and it will have syntax highlighting to catch a possible quote mismatch. otherwise, break the statements out in to separate lines if possible. 

Instead of mysql> source mysource.sql # you can use command prompt with --verbose option for more helpful output.


# mysql --verbose test < mysource.sql

What is services in drupal 8

 In Drupal 8, a service is any object managed by the services container. Drupal 8 introduces the concept of services to decouple reusable functionality and makes these services pluggable and replaceable by registering them with a service container.

Service  is a PHP class with some code that provides a single specific functionality throughout the application. So you can easily access each service and use its functionality wherever you need it. Because of that it is easy to test and configure in your application. This is called service-oriented architecture which is not unique to Symfony or even PHP.  

The Services and Dependency Injection Container concepts have been adopted by Drupal from the Symfony framework.  Accessing the database, sending email, or translating user interface are examples for the services in Drupal 8. 

How to define your own service in Drupal 8  through custom module Step are below.

1-  create the .info.yml  file [custom_services.info.yml]

name: Custom Services

type: module

description: The module provide the sample code to define  your service from  your custom module.

core: 8.x

package: Custom


2-  create the .services.yml file [custom_services.services.yml]

services:

 custom_services.say_hello:

   class: Drupal\custom_services\HelloServices 

 File name is ‘custom_services.services.yml’ where the ‘custom_services’ is our module name.

‘custom_services.say_hello’ is the service name defined by us, , Where we need to follow the pattern of ‘module_name’ concatenate with a ‘unique_name’.

We have the class name for services. ‘class: Drupal\custom_services\HelloServices’ which will be kept under the ‘src’ folder.

Also the dependency can be added the  following way 

arguments: ['@modulename.services1', '@modulename.services4', '@modulename.services7']  

In this case there are no  dependencies.

For more details visit https://www.drupal.org/node/2194463

3- Create the class ‘HelloServices.php’ under the ‘src’ folder

<?php

/**

* @file providing the service that say hello world and hello 'given name'.

*

*/

namespace  Drupal\custom_services;

class HelloServices {

 protected $say_something;

 public function __construct() {

   $this->say_something = 'Hello World!';

 }

 public function  sayHello($name = ''){

   if (empty($name)) {

     return $this->say_something;

   }

   else {

     return "Hello " . $name . "!";

   }

 }

}


This is simple class provide the service.

How to access the our own defined service?

Accessing the service globally. 

$service = \Drupal::service('custom_services_example.say_hello');

If you want to test this , you can enable the devel module and go to the path ‘devel/php’ and  run the following code 

$service = \Drupal::service('custom_services.say_hello');

dsm($service);

dsm($service->sayHello('Waliullah'));

So you will get the following output.

Drupal\custom_services\HelloServices Object

(   

      [say_something:protected] => Hello World!   

      [_serviceId] => custom_services.say_hello

)

 

Hello Waliullah!


For  more details please visit  the following links


https://www.drupal.org/node/2133171

http://symfony.com/doc/current/book/service_container.html

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...