2015 m. lapkričio 11 d., trečiadienis

2015 m. lapkričio 10 d., antradienis

Mysql Backup via CMD / cron

Visu failu backup i viena faila sugzipinta, su datos reiksme
mysqldump -u username -pPASWORDAS --opt --all-databases | gzip >   DailyDB_`date '+%Y-%m-%d_%T'`.sql.gz

Arba skriptas - backupu darymas i atskirus failus pagal duombazes
#!/bin/bash

USER="dfdsf"
PASSWORD="sdfdsf"
OUTPUT="/path/to/dir/"

databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database`

for db in $databases; do
    if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] ; then
        echo "Dumping database: $db"
        mysqldump -u $USER -p$PASSWORD --databases $db  | gzip > $OUTPUT/$db._`date '+%Y-%m-%d_%T'`.sql.gz
    fi
done
 you save the code in file backup.sh $ chmod +x

2015 m. rugsėjo 30 d., trečiadienis

php date interval

$dates = array_map(function($dt) { return $dt->format('Y-m');}, iterator_to_array(new DatePeriod(new DateTime(date('Y-m-01')), DateInterval::createFromDateString('-1 month'), 12)));

2015 m. rugsėjo 26 d., šeštadienis

SQL join`inimas po vieną naujausią eulutę

SELECT c.*, p1.*
FROM customer c
JOIN purchase p1 ON (c.id = p1.customer_id)
LEFT OUTER JOIN purchase p2 ON (c.id = p2.customer_id AND 
    (p1.date < p2.date OR p1.date = p2.date AND p1.id < p2.id))
WHERE p2.id IS NULL;
source: http://stackoverflow.com/questions/2111384/sql-join-selecting-the-last-records-in-a-one-to-many-relationship