Concatenation of Two Strings in PHP

AmitDiwan
Updated on 24-Dec-2019 12:13:08

243 Views

To concatenate two strings in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−1.967 and 1.969 Both the values are equal!ExampleLet us now see another example − Live DemoOutputThis will produce the following output−First Name = Jack Second Name = Sparrow Concatenation = JackSparrow

Comparing Float Value in PHP

AmitDiwan
Updated on 24-Dec-2019 12:10:38

769 Views

To compare float values in PHP, the code is as follows −Example Live DemoOutputThis will produce the following output−2.5 3.5 Both the values aren\'t equalExampleLet us now see another example − Live DemoOutputThis will produce the following example−1.967 1.969 Both the values are equal!

AND vs && Operators in PHP

AmitDiwan
Updated on 24-Dec-2019 12:08:08

2K+ Views

The difference is the precedence when we compare AND with && operator. The precedence of AND operator is lower than the operator = when the evaluation is performed, therefore even if both the operators do the same work, the result is different.ExampleLet us first see an example of the AND operator− Live DemoOutputThis will produce the following output−Result = TrueExampleLet us now see an example of the && operator− Live DemoOutputThis will produce the following output:Result = TrueExampleLet us now see the difference in a single example − Live DemoOutputThis will produce the following output−true false

Get Timezone Name in PHP

Samual Sam
Updated on 24-Dec-2019 10:22:52

61 Views

The timezone_name_get() function returns the name of the timezone.Syntaxtimezone_name_get(obj)Parametersobj − A DateTimeZone object.ReturnThe timezone_name_get() function returns array on success or FALSE on failure.ExampleThe following is an example − Live DemoOutputThe following is the output −Europe/Paris

Date Time Set Function in PHP

Samual Sam
Updated on 24-Dec-2019 08:43:08

78 Views

The date_time_set() function sets the time. It returns a DateTime object on success. FALSE on failure.Syntaxdate_time_set(obj, hour, minute, second)Parametersobj − DateTime objecthour − Hour of the time to setminute − Minute of the time to setsecond − Second of the time to setReturnThe date_time_set() function returns a DateTime object on success. FALSE on failure.ExampleThe following is an example − Live DemoOutputThe following is the output −2018-09-05 08:15:00ExampleLet us see another example − Live DemoOutputThe following is the output −2017-08-08 13:24:00

Connect Java to MySQL

AmitDiwan
Updated on 24-Dec-2019 07:58:15

530 Views

To connect Java to MySQL, the Java code is as follows −import java.sql.Connection; import java.sql.DriverManager; public class LostConnectionURLDemo {    public static void main(String[] args){       String JDBCURL="jdbc:mysql://localhost:3306/web?autoReconnect=true";       Connection con=null;        try{           con = DriverManager.getConnection(JDBCURL,"root","123456");           System.out.println("connection is established");        }       catch(Exception e){          e.printStackTrace();       }    } }This will produce the following output −

Sort Search Results Based on Substring Position in MySQL

AmitDiwan
Updated on 24-Dec-2019 07:55:43

228 Views

To sort search results based on substring position, use ORDER BY LOCATE(). Let us first create a table −mysql> create table DemoTable1838      (      Subject varchar(100)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1838 values('MongoDB MySQL'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1838 values('MySQL Java'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1838 values('JavaWithMySQL'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1838; This will ... Read More

Get Specific Column Record from SELECT Query in MySQL

AmitDiwan
Updated on 24-Dec-2019 07:54:20

497 Views

Let us first create a table −mysql> create table DemoTable1837      (      StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,      StudentName varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1837(StudentName) values('Chris'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1837(StudentName) values('David'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1837(StudentName) values('Bob'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1837(StudentName) values('Mike'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement ... Read More

Fix MySQL Error HASH1064 - SQL Syntax Error Near Type MyISAM

AmitDiwan
Updated on 24-Dec-2019 07:52:21

810 Views

This error occurs when we use TYPE for ENGINE NAME. The error is as follows −mysql> create table DemoTable1836      (      ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,      ClientName varchar(20)      )Type=MyISAM AUTO_INCREMENT=1; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Type=MyISAM AUTO_INCREMENT=1' at line 5Now, in MySQL 8, you can use ENGINE instead of Type. Let us first create a table −mysql> create table DemoTable1836      (      ClientId int NOT ... Read More

Fetch Random Rows in MySQL with Comma Separated Values

AmitDiwan
Updated on 24-Dec-2019 07:51:07

215 Views

To fetch random rows in MySQL, use ORDER BY RAND(). Let us first create a table −mysql> create table DemoTable1835      (      ListOfIds varchar(20)      ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1835 values('10, 20, 30'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1835 values('70, 80, 90'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1835 values('45, 67, 89'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1835 values('98, 96, 49'); Query OK, 1 row affected (0.00 ... Read More

Advertisements