AmitDiwan has Published 10744 Articles

Check whether property exists in object or class with PHP

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:50:33

3K+ Views

The property_exists() or the isset() function can be used to check if the property exists in the class or object.SyntaxBelow is the syntax of property_exists() function−property_exists( mixed $class , string $property )Exampleif (property_exists($object, 'a_property'))Below is the syntax of isset() function−isset( mixed $var [, mixed $... ] )Exampleif (isset($object->a_property))The isset() will ... Read More

Get all subdirectories of a given directory in PHP

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:45:37

2K+ Views

To get the subdirectories present in a directory, the below lines of code can be used −Example Live DemoOutputThis will produce the following output. The glob function is used to get all the subdirectories of a specific directory−Array (    [0] => demo.csv    [1] => mark.php    [2] => contact.txt ... Read More

Set 1 for NOT NULL value in MySQL

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:44:17

291 Views

To set NOT NULL, use IS NOT NULL and find the value. The syntax is as follows −select if('' is not NULL, 1, 0) as anyAliasName;Here is the working query −mysql> select if('' is not NULL, 1, 0);This will produce the following output −+------------------------+ | if('' is not NULL, 1, ... Read More

MySQL: How can I find a value with special character and replace with NULL?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:42:52

288 Views

For this, use SET yourColumnName = NULL as in the below syntax −update yourTableName set yourColumnName=NULL where yourColumnName=yourValue;Let us first create a table −mysql> create table DemoTable1914    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Code varchar(20)    )AUTO_INCREMENT=1001; Query OK, 0 rows affected (0.00 sec)Insert some ... Read More

PHP Regex to get YouTube Video ID

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:41:43

768 Views

The parse_url and parse_str functions can be used to get the ID of a specific YouTube video.Example Live DemoOutputVX96I7PO8YUIn the above code, the parse_url function takes in a string and slices it into an array of information. The element that the user specifically wants to work with can be specified as ... Read More

How to append 000 in a MySQL column value?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:39:20

205 Views

To append 000, use the concept of ZEROFILL. Let us first create a table −mysql> create table DemoTable1913    (    Code int(4) ZEROFILL AUTO_INCREMENT NOT NULL,    PRIMARY KEY(Code)    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into ... Read More

How to capture the result of var_dump to a string in PHP?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:38:35

2K+ Views

The resultant value of var_dumo can be extracted to a string using ‘output buffering’. Below is an example demonstrating the same −Example Live Demo

How to update User Logged in Time for a specific user in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:37:07

224 Views

For this, use ORDER BY along with LIMIT. Let us first create a table wherein we have a column with User id, logged in time, and name −mysql> create table DemoTable1911    (    UserId int,    UserLoggedInTime time,    UserName varchar(20)    ); Query OK, 0 rows affected (0.00 ... Read More

A Preferred method to store PHP arrays (json_encode or serialize)?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:36:39

467 Views

This depends on the requirements in hand.JSON is quicker in comparison to PHP serialization unless the following conditions are met−Deeply nested arrays are stored.The objects that are stored need to be unserialized to a proper class.The interaction is between old PHP versions that don't support json_decode.The below line of code ... Read More

Perform count with CASE WHEN statement in MySQL?

AmitDiwan

AmitDiwan

Updated on 30-Dec-2019 06:34:51

602 Views

For this, you can use CASE WHEN statement. Let us first create a table −mysql> create table DemoTable1910    (    FirstName varchar(20),    Marks int    ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1910 values('Chris', 45); Query ... Read More

Advertisements