This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# db_fetch_object | |
// Drupal 6 | |
while ($record = db_fetch_object($result)) { | |
// Do stuff with $record, which is an object | |
} | |
// Drupal 7 | |
foreach ($result as $record) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @serial=0; | |
SELECT @serial := @serial+1 AS `serial_number` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The difference between two folders | |
diff folder_1 folder_2 | |
# The difference between two files | |
diff file_1.txt file_2.txt | |
# The difference between two folders recursive | |
diff -r folder_1 folder_2 | |
# Create a patch file from a diff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT COUNT(*) AS users, COUNT(IF(a.active BETWEEN '2013-09-01 00:00:00' AND '2013-09-31 23:59:59',1,NULL)) AS active | |
FROM lsoncc_Users AS u | |
LEFT JOIN lsoncc_UsersFlags AS a | |
ON u.userid = a.userid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = '/tmp/file.xml'; | |
if (file_exists($file)) { | |
header('Content-Description: File Transfer'); | |
header('Content-Type: application/octet-stream'); | |
header('Content-Disposition: attachment; filename='.basename($file)); | |
header('Content-Transfer-Encoding: binary'); | |
header('Expires: 0'); | |
header('Cache-Control: must-revalidate'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
drupal_mail( 'control_centre_feed', 'feed', '[email protected]', language_default(), $params, '[email protected]'); | |
function control_centre_feed_mail ($key, &$message, $params) { | |
switch ($key) { | |
case 'feed': | |
$message['subject'] = t($params['filename']); | |
$message['body'][] = t($params['filepath']); | |
break; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// createFile function | |
function createFile($filename) { | |
// Declare content | |
$content = "Some content here"; | |
$morecontent = "And some more content here"; | |
// Add content to file | |
file_put_contents( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create fqdn file in conf.d and add localhost | |
$ echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn | |
//File path and gedit to add vhost, so that it will resolve to localhost | |
sudo gedit /etc/hosts | |
//Restart Apache | |
$ sudo /etc/init.d/apache2 restart | |
// Sites available folder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Backup using mysqldump | |
mysqldump my_database > database_backups/my_database_backup.dump; | |
// Restore using mysql | |
mysql> create database my_database_restore; | |
mysql> use my_database_restore; | |
mysql> source database_backups/my_database_backup.dump; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT dob FROM from table | |
-- all dob between 20 and 25 years of age | |
WHERE FLOOR(DATEDIFF(now(), CAST(dob AS DATE))/365.25 ) BETWEEN 20.0 AND 25.0 | |
-- all dob equal or older than 40 | |
AND Year(Curdate()) - Year(dob) - ( Right(Curdate(),5) < Right(u.dob,5)) <= 40 | |
-- dob within the last six months | |
AND dob >= DATE_SUB(NOW(), INTERVAL 6 MONTH) |