Category : MySql


How to connect mysql database in node js with example?

Node.js is very popular in Todays for make chat system, real-time notification, real-time developing etc. So, Today, I am going to give you very simple example of How to use MySQL Query in Node JS. If you use node.js then you can see how it is work and there are several driver for different task like redis, socket io, express etc. But Node.js have a driver for MySQL that way we can easily connect with database and you can use select, insert, update and delete sql query. So, in this example i going to give from scratch so if you are beginner and you haven't installed nodejs on your server th.....

By Hardik Savani | September 29, 2016 | | 1369 Viewer | Category : MySql
READ MORE

How to get last 2 days records from table using Mysql Query?

We may sometimes require to get few days ago records from table like last 2 days, last 3 days, last 10 days or last 15 days etc. Most of developer choose other logic but we can easily get using mysql query(using CURDATE and INTERVAL). In this example mysql query i have one table "elements" and columns are id, title, description, created_at(timestamps) and update_at, Now we will get all records of last 2 days.so you can fetch fields value using CURDATE and INTERVAL of mysql. In following example you can see how to select data of last two days. <strong>Query:</strong> <pre> SELECT * FROM `elem.....

By Hardik Savani | July 22, 2016 | | 1251 Viewer | Category : MySql
READ MORE

How to get current year rows using MySql Query PHP?

If you require to get all the records of current year using mysql query. for example you have one table "items" and columns are id, title, description, created_at and update_at, Now you want to get all records of this year. so you can fetch fields value using DATE_SUB and INTERVAL of mysql. In following example you can see how to select data of current year. <strong>Example:</strong> <pre> SELECT * FROM items WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 YEAR); </pre>

By Hardik Savani | June 14, 2016 | | 731 Viewer | Category : MySql
READ MORE

How to calculate age from date of birth column in mysql?

Sometimes, we require to get age from birthdate using mysql select query, we can do it in programming like php,.net and etc framework but if we can do it using mysql query. In bellow example mysql query you can learn how to get age from date field. We can get age value from using mysql DATEDIFF(). So, let's see bellow query. <strong>Example:</strong> <pre> SELECT id, (DATEDIFF(CURRENT_DATE, STR_TO_DATE(born_date, '%Y-%m-%d'))/365) as age FROM `users` </pre>

By Hardik Savani | June 1, 2016 | | 1493 Viewer | Category : MySql
READ MORE

How to rename column name foreign key constraint in MySql Query?

This is more one post on mysql query, I don't remember exactly time but i had need to change name of foreign key constraint column field. We can rename field name easily if we didn't set foreign key constraint. But if you set foreign key constraint then you can't rename easily. I had rename directly from my phpmyadmin without mysql query but i found bellow error: <pre> Query error: #1025 - Error on rename of './learn/#sql-46c_246' to './learn/my_table' (errno: 150) </pre> But i found the solution of mysql rename foreign key constraint using mysql query, First we have to drop the foreign key,.....

By Hardik Savani | May 4, 2016 | | 3465 Viewer | Category : MySql
READ MORE

Example of trigger on after delete with update query mysql

Sometimes we need to fire trigger like after delete update some fields of another tables. for example if you have chat_message tables and when remove row on this table then we need to update "remove_counter(remove_counter + 1)" on users table. i did give you bellow example you can see how to write trigger code: <strong class="example">Example:</strong> <pre class="prettyprint lang-php"> delimiter // CREATE TRIGGER add_ban_counter_in_users AFTER DELETE ON `chat_messages` FOR EACH ROW BEGIN UPDATE `users` SET remove_counter = users.remove_counter + 1 WHERE users.id = old.user_id.....

By Hardik Savani | April 5, 2016 | | 1057 Viewer | Category : MySql
READ MORE

How to get current month data in MySql PHP ?

If you require to get all the records of current month using mysql query. for example you have one table "items" and columns are id, title, description, created_at and update_at, Now you want to get all records of this month. so you can fetch fields value using DATE_SUB and INTERVAL of mysql. In following example you can see how to select data of current month. <strong class="example">Example:</strong> <pre class="language-mysql">SELECT * FROM items WHERE created_at > DATE_SUB(NOW(), INTERVAL 1 MONTH);</pre>

By Hardik Savani | March 17, 2016 | | 2589 Viewer | Category : MySql
READ MORE

Sql function remove numeric characters from column example

Mysql custom fucntion is a very prety and intresting concept. In this posts i want to create one custom mysql function for remove numeric characters from table field value. this function through you can also remove numeric characters from string in mysql. in following sql query fire in your mysql or mssql database and check how it works. So, lets create function and how to use in select statement in sql query. <strong class="step">Create removeNumber function:</strong> <pre class="prettyprint lang-mysql"> DROP FUNCTION IF EXISTS removeNumber; DELIMITER | CREATE FUNCTION removeNumber( str CH.....

By Hardik Savani | March 12, 2016 | | 753 Viewer | Category : MySql
READ MORE

How to remove special characters by mysql custom function.

Mysql custom fucntion is a very prety and intresting concept. In this posts i want to create one custom mysql function for remove special characters from table field value. this function through you can also remove special characters from string in mysql. in following sql query fire in your mysql or mssql database and check how it works. So, lets create function and how to use in select statement in sql query. <strong class="step">Create removeSpacialChar function:</strong> <pre class="prettyprint lang-mysql"> CREATE FUNCTION `removeSpacialChar`(`in_str` varchar(4096)) RETURNS varchar(4096) C.....

By Hardik Savani | March 10, 2016 | | 2947 Viewer | Category : MySql
READ MORE

How to use where clause with mysql function in Laravel 5?

When you are working on laravel projects and you need to use mysql function in where clause then you can easily use that using DB::raw() and whereRaw(). In this example you can show how to i use mysql function in where clause. In this example i want to compare with year of created_at field but not whole date, that's whay i use mysql function Year(), this function will return only year from timestamp and compare with given value. I add two example of how to use sql function in where cause. let's See both example. <strong class="example">Example 1:</strong> <pre class="prettyprint lang-sql"> $da.....

By Hardik Savani | March 9, 2016 | | 2167 Viewer | Category : MySql
READ MORE

    How to make simple dependent dropdown using jquery ajax in Laravel 5?

    How to make simple dependent dropdown using jquery ajax in Laravel 5?

    Open Post

    Laravel 5 Redirect to URL using redirect() helper

    Laravel 5 Redirect to URL using redirect() helper

    Open Post

    PHP Codeigniter - Ajax Infinite Scroll Pagination Example

    PHP Codeigniter - Ajax Infinite Scroll Pagination Example

    Open Post

    Angularjs nl2br(textarea newline and linebreak conversion) example with demo

    Angularjs nl2br(textarea newline and linebreak conversion) example with demo

    Open Post

    Laravel 5 - Dynamic Dependant Select Box using JQuery Ajax Example - Part 2

    Laravel 5 - Dynamic Dependant Select Box using JQuery Ajax Example - Part 2

    Open Post

    Laravel 5 - Twitter API using thujohn/twitter composer package tutorial

    Laravel 5 - Twitter API using thujohn/twitter composer package tutorial

    Open Post