Search Results For: shortener
Showing 1 to 1 of 1 blog articles.
6028 views · 228 days ago

![Creating a URL shortener application in PHP & MySQL](https://images.ctfassets.net/vzl5fkwyme3u/3OjKfmylv2k8eWayqeCUWG/6d8e996fc7c757135df7fdd322fd50a4/AdobeStock_65694631.jpeg?w=1000)

Hi Guys,

In this post we will learn how to create your URL shortening application in PHP and MySQL.

You may also use this app as an API by calling the URLs from another application.

## Step 1: Creating a Table

```mysql

CREATE TABLE IF NOT EXISTS `url_shorten` (

`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,

`url` tinytext NOT NULL,

`short_code` varchar(50) NOT NULL,

`hits` int(11) NOT NULL,

`added_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

```

## Step 2: Create a file `index.php` and add database credentials in it

```php

$servername = 'localhost';

$username = 'root';

$password ...

    SPONSORS

    Faster PHP Cloud Hosting