Mysql Yesterday and other web programing tips
SSH commands
- Export data from tar
- tar -xvf "filename"
- Make zip archive through ssh
- zip -r pavadinimas.zip /home/httpd/vhosts/saitovardas.com/httpdocs
- Make tar archive on ssh
- tar -cvvf bak.tar /usr/public_html/
- Make mysqldump through ssh (backup mysql data)
- mysqldump -e --force --quick --quote-names -h localhost -u root -p DBNAME > BACKUP_FILE.sql
- Restore mysql data through ssh (import mysql data)
-
mysql -u USER -p DBNAME < dump.sql - Ownerio pakeitimas
- chown host1plus:host1plus ./* -R
- Failo paieška direktorijoje
- find /home/host1plus/public_html/support -name "*failo_vardo*"
- Teksto paieška direktorijoje
- grep -irE "regexpas ko ieskai" /direktorija/
- MYSQL REPLACE
- UPDATE mc_products set `description`=replace(`description`, 'what', 'with what')
- Other mysql queries examples
- http://www.1keydata.com/sql
Also usefull free mysql tool (community edition)
Tools
PHP syntax
($this->userId)?$this->userId:0;
SQL queriesUPDATE mc_products set `description`=replace(`description`, 'what', 'with what')
Delete dublicate rows
DELETE tablename
FROM tablename,
(SELECT MAX(uid) AS dupid,COUNT(uid) AS dupcnt
FROM tablename
GROUP BY id,url HAVING dupcnt>1)
AS dups
WHERE tablename.uid=dups.dupid;
$cn= mysql_connect("localhost", "root", "") or die('Could not connect');
$db= mysql_select_db(test, $cn) or die('Could not select database');
$query="SELECT * FROM name";
$result=mysql_query($query);
echo mysql_error();
while($row = mysql_fetch_array($result, MYSQL_BOTH))
{
$query1="SELECT * FROM tablename where name = '".$row[1]."'";
$result1=mysql_query($query1);
$count = mysql_num_rows($result1) - 1;
mysql_query("DELETE FROM tablename WHERE name='".$row[1]."' LIMIT $count",$link);
echo "deleted $row[1] ";
}
echo mysql_error();
Yesterday
SELECT * FROM table WHERE time_field >= DATE_SUB(CURRENT_DATE(), INTERVAL 1 DAY)
Tutorials
PHP
htaccess
Enable PHP debugging using .htaccess
php_flag display_errors on
# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
# enable PHP error logging
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
Adding PHP mime type to JS:
AddHandler x-httpd-php5 .js
MySQL
Design
AJAX