Found 1046 Articles for PHP

Concatenation of two strings in PHP

Alok Prasad
Updated on 30-Jul-2019 22:30:26

3K+ Views

PHP offers different kinds of operators having distinctive functionalities. Operators enable us to perform arithmetic activities, string concatenation, compare values and to perform boolean operations, more...In this article, we will learn string operators given by PHP. Let's first learn the types of string operators in php. There are two string operators provided by PHP.  1.Concatenation Operator ("."):      This operator combines two string values and returns it as a new string. 2.Concatenating Assignment operator (".="):      This operation attaches the argument on the right side to the argument on the left side. Let's demonstrate the utility of the above operators by following examples.Example:Output ... Read More

Comparison of dates in PHP

Alok Prasad
Updated on 30-Jul-2019 22:30:26

6K+ Views

Matching two dates in PHP is quite smooth when both the dates are in a similar format but php failed to analyze when the two dates are in an unrelated format. In this article, we will discuss different cases of date comparison in PHP. We will figure out how to utilize DateTime class, strtotime() in comparing dates.Case 1:we can analyze the dates by simple comparison operator if the given dates are in a similar format.Output:2019-03-26 is latest than 2018-11-24Explanation:Here we have declared two dates $date1 and $date2 in the same format. So we have used a comparison operator(>) to compare ... Read More

Is PHP deg2rad() equal to MySQL radians()?

George John
Updated on 30-Jul-2019 22:30:25

70 Views

Yes, both of these methods convert a degree value to radian. Let us create a table to understand MySQL radians. The query to create a table is as followsmysql> create table RadiansDemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > Value int    - > ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into RadiansDemo(Value) values(0); Query OK, 1 row affected (0.14 sec) mysql> insert into RadiansDemo(Value) values(45); Query OK, 1 row affected (0.17 sec) mysql> insert into ... Read More

Extracting only date from datetime field in MySQL and assigning it to PHP variable?

Samual Sam
Updated on 30-Jul-2019 22:30:25

581 Views

You need to use DateTime class if you want to extract the only date from datetime field. The syntax is as follows −DateTime::createFromFormat("Y-m-d H:i:s",yourDateTimeValue)->format("yourFormatSpecifier");Now you can implement the above syntax in your PHP code to extract the only date from datetime field. The PHP code is as follows −$MySQLDataBaseDateTime = "2018-02-13 13:10:15"; echo DateTime::createFromFormat("Y-m-d H:i:s",$MySQLDataBaseDateTime)->format("d/m/Y");Here is the screenshot of the PHP code −Output13/02/2018

How to add auto-increment to column in MySQL database using PhpMyAdmin?

karthikeya Boyini
Updated on 26-Jun-2020 10:21:02

9K+ Views

You can add auto_increment to a column in MySQL database with the help of ALTER command.The syntax is as follows −ALTER TABLE yourTableName MODIFY yourColumnName INT NOT NULL AUTO_INCREMENT;To open PhpMyAdmin on localhost, you need to type the following on localhost and press enter −localhost/phpmyadminThe screenshot is as follows −Above, we already have a table “AutoIncrementDemo”. In that, we have a column “UserId” set as Primary key. Let’s say we need to add auto_increment to the same column.For auto_increment, check the A.I as shown above. The same is marked below as well −After that press the Save button.Let us also ... Read More

How can I get enum possible values in a MySQL database using PHP?

Samual Sam
Updated on 26-Jun-2020 09:59:16

2K+ Views

You can get the enum possible values in a MySQL database with the help of INFORMATION_SCHEMA.COLUMNS table. The syntax is as follows −SELECT    COLUMN_TYPE AS anyAliasName FROM    INFORMATION_SCHEMA.COLUMNS WHERE    TABLE_SCHEMA = ‘yourDatabaseName’ AND TABLE_NAME = 'yourTableName' AND COLUMN_NAME = 'yourEnumColumnName';To understand the above syntax, let us create a table with an ENUM data type. The query to create a table is as follows −mysql> create table EnumDemo -> ( -> Id int, -> Color ENUM('RED', 'GREEN', 'BLUE', 'BLACK', 'ORANGE') -> ); Query OK, 0 rows affected (0.66 sec)Here the table ‘EnumDemo’ is present in the ‘sample’ database. ... Read More

Extract the Day / Month / Year from a Timestamp in PHP MySQL?

Samual Sam
Updated on 30-Jul-2019 22:30:24

745 Views

To extract the Day/Month/Year from a timestamp, you need to use the date_parse() function. The syntax as follows −print_r(date_parse(“anyTimeStampValue”));The PHP code is as follows −$yourTimeStampValue="2019-02-04 12:56:50"; print_r(date_parse($yourTimeStampValue));The snapshot of PHP code is as follows −The following is the output −Array ( [year] => 2019 [month] => 2 [day] => 4 [hour] => 12 [minute] => 56 [second] => 50 [fraction] => 0 [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => )The snapshot of the sample output −

How to specify Decimal Precision and scale number in MySQL database using PHPMyAdmin?

Chandu yadav
Updated on 30-Jul-2019 22:30:24

2K+ Views

You need to select a database when you are creating a table. Right now, I have a sample database. The snapshot is as follows:Now you need to give the table name as well as the number of columns you want:After that you need to press Go button. Now, the following section would be visible:The DECIMAL requires two parameter i.e. Total Number of Digit and second one is DigitAfterDecimalPoint.The structure of DECIMAL is as follows:DECIMAL(X, Y)Here, X is TotalNumberOfDigit and Y is DigitAfterDecimalPoint.Let us see an example:DECIMAL(6, 4)Above, we will be having 6 digit sand 2 digit safter decimal point. For ... Read More

imagecreatetruecolor() function in PHP

Arjun Thakur
Updated on 31-Dec-2019 08:05:48

694 Views

The imagecreatetruecolor() function creates a new true color image.Syntaximagecreatetruecolor (width , height )Parameterswidth: The image width.height: The image height.ReturnThe imagecreatetruecolor() function returns an image resource identifier on success, FALSE on errors.ExampleThe following is an example Live DemoOutputThe following is the output displaying the height and width of the new image:500 600ExampleLet us see another example with different height and width: Live DemoOutputThe following is the output displaying the height and width of the new image:450 300

imageconvolution() function in PHP

Chandu yadav
Updated on 31-Dec-2019 08:00:58

84 Views

The imageconvolution() functionSyntaxbool imageconvolution (img, matrix, div, offset )Parametersimg: Create image with imagecreatetruecolor() function.matrix: A 3x3 matrix is an array of three arrays of three floats.div: Divisor of the result of the convolution, used for normalization.offset: The color offset.ReturnThe imageconvolution() function returns True on success or False on failure.ExampleThe following is an exampleOutputThe following is the outputExampleLet us see another example with different parameter values for the same image. You can easily spot the difference now:OutputThe following is the output

Advertisements