Automatic Database and file Backup with PHP

phpMyBackup Pro is a very easy to use, free, web-based MySQL backup application, licensed under the GNU GPL.
You can create scheduled backups, manage and restore them, download or email them and a lot more!

Major features:

– backup of one or several databases with or without data, table structure, …
– three types of compression (no compression, gzip or zip)
– scheduled backups (by a small PHP script which must be included in an existing PHP script)
– interface for managment of the backups (viewing, restoring, downloading, deleting)
– backup directly onto FTP server and sending of backups by email
– platform independent – only webserver and PHP needed to run e.g. on MS Windows, Linux or Mac
– shell mode (to use manually or by cron script)
– backup of whole file directories (on a FTP server).
– backup databases from different accounts on several MySQL servers
– one installation can be used for all MySQL users of one MySQL server (used by webhosters)
– highest security through two alternative login methods (HTTP or HTML authentication)
– easy to use interface and very easy to install
– several language packages available
– online help (included in pMBP) and FAQ on this website

========

to automate it, you must set cron like this:

wget -O /dev/null http://domain.com/script_dirr/auto_name.php

MySQL Data Types Digest

Type Storage Minimum Value Maximum Value
(Bytes) (Signed/Unsigned) Signed/Unsigned)
TINYINT 1 -128 127
0 255
SMALLINT 2 -32768 32767
0 65535
MEDIUMINT 3 -8388608 8388607
0 16777215
INT 4 -2147483648 2147483647
0 4294967295
BIGINT 8 -9223372036854775808 9223372036854775807
0 18446744073709551615

The CHAR and VARCHAR types are similar, but differ in the way they are stored and retrieved. As of MySQL 5.0.3, they also differ in maximum length and in whether trailing spaces are retained.

The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.

The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.

Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.

In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.

If strict SQL mode is not enabled and you assign a value to a CHAR or VARCHAR column that exceeds the column’s maximum length, the value is truncated to fit and a warning is generated. For truncation of nonspace characters, you can cause an error to occur (rather than a warning) and suppress insertion of the value by using strict SQL mode.

For VARCHAR columns, trailing spaces in excess of the column length are truncated prior to insertion and a warning is generated, regardless of the SQL mode in use. For CHAR columns, truncation of excess trailing spaces from inserted values is performed silently regardless of the SQL mode.

VARCHAR values are not padded when they are stored. Handling of trailing spaces is version-dependent. As of MySQL 5.0.3, trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL. Before MySQL 5.0.3, trailing spaces are removed from values when they are stored into a VARCHAR column; this means that the spaces also are absent from retrieved values.

Value CHAR(4) Storage Required VARCHAR(4) Storage Required
'' '    ' 4 bytes '' 1 byte
'ab' 'ab  ' 4 bytes 'ab' 3 bytes
'abcd' 'abcd' 4 bytes 'abcd' 5 bytes
'abcdefgh' 'abcd' 4 bytes 'abcd' 5 bytes

for more info:

http://dev.mysql.com/doc/refman/5.0/en/char.html

===============

 

Mysql Get Query Digest

require(constant("sec_inc").'/config.php');
$link=mysql_connect($host,$user,$pass);
mysql_select_db($dbname);

Fetch:

$query = "select * from table_name  where field='".$var."'";//Don't forget escaping...
mysql_query("SET NAMES 'utf8'", $link);
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
{

         //Bla Bla Bla

}

 

Count:

$query = "select count(*) from table_name  where field='".$var."'";//Don't forget escaping...
$row=mysql_fetch_row($result);
$count = $row[0];