Tag Archive

How to replace substring in MySQL table field

Published on March 11, 2011 By admin

This replace will search in every row of the table where condition from WHERE is true and replace function will replace all instances in a string. ex. if you have text “hello world” and you want to replace the “o” letter with “*” this will will transform the text in “hell* w*rld” UPDATE `mytable` SET [...]

MySQL: Select “last month” records

Published on February 4, 2011 By admin

In order to select last month records you have to get first dai of the last month and the last day of the first month. Remember that current month could be January and the last month will in another year. Finding first day of the last month: DATE_FORMAT(CURRENT_DATE – INTERVAL 1 MONTH, "%Y-%m-01") Finding the [...]

MySQL: select “this month” records

Published on February 4, 2011 By admin

Where “date” column is a Date type in “my_table” SELECT * FROM `my_table` WHERE YEAR(`DATE`) = YEAR(CURDATE()) AND MONTH(`DATE`) = MONTH(CURDATE())

MySQL: Select last 7 days records

Published on February 4, 2011 By admin

For this example I use this table model: ID Name Date 1 Jon Dow 2011-01-10 2 Jane Dow 2011-01-10 … … … SELECT * FROM `my_table` WHERE `DATE` BETWEEN DATE_ADD(CURDATE(), INTERVAL -5 DAY) AND CURDATE()

MySQL: Select today, yesterday or day before yesterday records

Published on January 10, 2011 By admin

Usualy when you work with records where a date or timestamp field is present you need to select records from: today records yesterday records day before yesterday records Lets say you have a table (my_table) like this: ID Name Date 1 Jon Dow 2011-01-10 2 Jane Dow 2011-01-10 … … … where `Date` is date [...]

Neural Networks in PHP

Published on March 9, 2010 By admin

Browsing phpclasses.org I had found a very interesting article Neural Networks in PHP . For anyone who dont know yet “Neural networks allow emulating the behavior of a human brain in software applications.” In this article you can read how to implement Neural Mesh to develop Neural Network applications in PHP. (Neural Networks in PHP) [...]

Restore MySql database using command line

Published on December 17, 2009 By admin

mysql -u USER -p DBNAME < dump.sql Where: USER is your username DBNAME is Databas witch will be restored dump.sql (any .sql file can be used) is your database dump

Format PHP Date to MySQL Format

Published on May 17, 2008 By admin

When you insert or update a date in a mysql Table you have to remember that Mysql have 3 types of date DATETIME         ( default format 0000-00-00 00:00:00 ) DATE                ( default format 0000-00-00 ) TIMESTAMP      ( default format 0000-00-00 00:00:00 ) PHP code:       DATE ->  $mysqldate = date( ‘Y-m-d’ );       DATETIME, TSTAMP [...]

MySQL variables range

Published on April 24, 2008 By admin

TINYINT A very small integer The signed range is –128 to 127. The unsigned range is 0 to 255. SMALLINT A small integer The signed range is –32768 to 32767. The unsigned range is 0 to 65535 MEDIUMINT A medium-size integer The signed range is –8388608 to 8388607. The unsigned range is 0 to 16777215 [...]