Learning PHP and MySQL

Monday, August 07, 2006

Example 08-05 Calculating the length of a string

SELECT CONCAT(`title`,' has 'LENGTH(`title`), ' characters.'FROM `books`;

Posted by krautgrrl on 08/07 at 05:13 PM
Chapter 8 Code • (0) Comments • (1) TrackbacksPermalink

Example 08-06 Changing the case of the title

SELECT UCASE(`title`), LCASE(`title`) from `books`;

Posted by krautgrrl on 08/07 at 05:13 PM
Chapter 8 Code • (2) Comments • (1) TrackbacksPermalink

Example 08-07 Using the LEADING option to remove zeros

SELECT TRIM(LEADING '0' from '0000Example00000');

Posted by krautgrrl on 08/07 at 05:13 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-08 Using TRIM with the TRAILING option

SELECT TRIM(TRAILING '0' from '0000Example00000');

Posted by krautgrrl on 08/07 at 05:14 PM
Chapter 8 Code • (0) Comments • (1) TrackbacksPermalink

Example 08-09 Looking for the string in our author names

SELECT LOCATE`author`,LOCATE('on',`author`) FROM `authors`;

Posted by krautgrrl on 08/07 at 05:14 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-10 Adding the formatting to a phone number using LEFT, RIGHT, and SUBSTR

SELECT CONCAT('('LEFT('6128238193',3),
')'SUBSTR('6128238193',4,3),
'-',
RIGHT('6128238193'4));

Posted by krautgrrl on 08/07 at 05:15 PM
Chapter 8 Code • (26) Comments • (1) TrackbacksPermalink

Example 08-11 Using WEEKDAY to get the day of the week

SELECT WEEKDAY('1964-10-12');

Posted by krautgrrl on 08/07 at 05:15 PM
Chapter 8 Code • (1) Comments • (0) TrackbacksPermalink

Example 08-12 Using DAYNAME to get the day of the week as a name

SELECT DAYNAME('1964-10-12');

Posted by krautgrrl on 08/07 at 05:16 PM
Chapter 8 Code • (2) Comments • (0) TrackbacksPermalink

Example 08-13 Finding days since the start of the year

SELECT DAYOFYEAR('2006-1-1'), DAYOFYEAR('2006-12-24');

Posted by krautgrrl on 08/07 at 05:16 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-14 Using MONTH and MONTHNAME on the purchases table

SELECT `day`,MONTH(`day`),MONTHNAME(`day`) FROM `purchases`;

Posted by krautgrrl on 08/07 at 05:16 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-15 Using HOUR and MINUTE on a time

SELECT CONCAT_WS(':',hour('4:46:45'),MINUTE('4:46:45'));

Posted by krautgrrl on 08/07 at 05:17 PM
Chapter 8 Code • (0) Comments • (1) TrackbacksPermalink

Example 08-16 Using DATE_SUB to subtract days

SELECT DATE_SUB(NOW(), INTERVAL 12 DAY);

Posted by krautgrrl on 08/07 at 05:17 PM
Chapter 8 Code • (26) Comments • (1) TrackbacksPermalink

Example 08-17 Using the minus operator on a date

SELECT NOW()-INTERVAL 12 DAY;

Posted by krautgrrl on 08/07 at 05:18 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 08-18 Using DATE_FORMAT with a string to place colons between the segments

SELECT DATE_FORMAT('2006-12-24 09:09:23''%h:%i:%s');

Posted by krautgrrl on 08/07 at 05:18 PM
Chapter 8 Code • (0) Comments • (0) TrackbacksPermalink

Example 09-01 PHP file format

<?php
$db_host
='hostname of database server';
$db_database='database name';
$db_username='username';
$db_password='password';
?>

Posted by krautgrrl on 08/07 at 05:20 PM
Chapter 9 Code • (0) Comments • (248) TrackbacksPermalink
Page 2 of 3 pages  <  1 2 3 >

Statistics

This page has been viewed 375225 times
Page rendered in 0.3173 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 8
Total anonymous users: 0
Most Recent Visitor on: 02/10/2012 10:22 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm

Referrers

Powered by ExpressionEngine