PHP & MySQL

MySQL: Select today, yesterday or day before yesterday records

Posted by admin on January 10, 2011 at 11:29 am

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 [...]

Make your own custom Facebook and Twitter share buttons

Posted by admin on December 11, 2010 at 9:53 pm

Sometimes Share button from Facebook and Twit button from Twitter do not fit in your website/blog. So you design a great Share button Image but how to link it to your own article with title and permalink. For Twitter: – send the visitor to this link: http://twitter.com/share?_=1292093673417&count=horizontal&original_referer=your_page_link_url_encoded&related=your_twitter_account&text=page_title_or_text_html_encoded&url=your_page_link_url_encoded&via=your_twitter_account If you want to implement this in WordPress [...]

Substract 1 hour from current date in PHP

Posted by admin on December 8, 2010 at 9:41 am

This 3 lines will give you the current date minus 1 hour: $date = date("d-m-Y H:i"); $newdate = strtotime ( ‘-1 hour’ , strtotime ( $date ) ) ; $newdateStr = date (‘d-m-Y H:i’ , $newdate );

Getting phpDocumentor to work

Posted by admin on November 25, 2010 at 4:39 pm

Today I needed phpDocumentor to work but after install surprinse !!! Is not working. In every documentation generated by phpdoc a Smarty error is present: Warning: Smarty error: unable to read resource: “pkgelementindex.tpl” in … or Warning: Smarty error: unable to read resource: “top_frame.tpl” in … or … So after hours of code debbuging I found that [...]

How to display all Global variables in PHP

Posted by admin on August 25, 2010 at 9:56 pm

Sometimes when debugging an application you need to see all global variables. In PHP there is an easy way: $defined_vars = get_defined_vars(); print_r($defined_vars);

New Line in PHP

Posted by admin on March 31, 2010 at 9:52 pm

Printing a new line witch is visible in a web page is made like this: echo(‘line 1′.‘\n‘.‘line 2′);   the code above will print line 1 on a line and line 2 on a new line. Now if you have to generate a CSV file  <br/> wil not work  you have to use  \n like [...]

Neural Networks in PHP

Posted by admin on March 9, 2010 at 12:43 pm

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

Posted by admin on December 17, 2009 at 1:55 pm

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

Posted by admin on May 17, 2008 at 2:07 am

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

Posted by admin on April 24, 2008 at 7:08 pm

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 [...]