Archive for March, 2008

mysql backup

usage
#mysqldump [options] db_name [tables]
#mysqldump [options] –databases db_name1 [db_name2 db_name3...]
#mysqldump [options] –all-databases
Example
#mysqldump -u root -p mydatabase > db.sql
Specific table
#mysqldump -u root -p mydatabase -tables customer > db.sql
How to restore database
#mysql -u root -p database < db.sql
If want to restore to specific database
mysql -u root -pMyPassword MyDatabase < db.sql


Simple PHP Cache Manager Class

This class can be used to cache arbitrary data in files.
It can check if the cache with a certain key already exists. If it exists and it is not expired, it can return the cached data. Otherwise it can store newly generated data in a cache file with the given key.
The class can be configured [...]


PHP functions to Apache handle.htpasswd file

?View Code PHP< ?php
/*
 
Author : Mitko Kostov
Weblog : http://mkostov.wordpress.com
Mail :mitko.kostov@gmail.com
Date : 12/21/2007
Used : PHP and Smarty
 
*/
// function to register user
function regUser() {
$filename = ‘members/password/.htpasswd’;
$data = $_POST[’username’].":".htpasswd($_POST[’password’])."\n";
[...]


PHP Cookie Handler Class

This class allows for the handling of normal and serialized cookies as well as switching between these types of cookies.
Cookie Functions:
Write Cookies
Read Cookies
Delete Cookies
Use of this class is fairly simple.
Step 1: Include the class source in your php project using the require or include statement.
Step 2: Instance the cookie class by using the new keyword. [...]


PHP generate new an resizing image

?View Code PHP< ?PHP
class HanroadClass
{
/************************
generate new an Resizing image by the PHP GD library
Support picture format: jpg, gif, png
$source_img: Source image path
$target_dir: Target image path
$target_name: Target image name
$new_width: Target image width
$new_height: [...]


package transforming all php errors into catchable exceptions

This package can be used to turn PHP run-time errors into catchable exceptions.
It sets the PHP error handler function to point to a class function that will throw exceptions when an error occurs.
The class throws exceptions of different classes according to the type of PHP error that occurred.
All exception classes are derived from a common [...]


A calendar code

This class can be used to display month calendars in HTML tables.
It takes a given month and year and generates an HTML table with the days of that month. The calendar start week day may be set to Sunday or Monday.
Special event days may exhibit the title of the event in the respective calendar table [...]


PHP read Excel

?View Code PHP 
< ?php
/**
* <?php
* require "excel_class.php";
* Read_Excel_File("Book1.xls",$return);
* for ($i=0;$i<count($return[Sheet1]);$i++)
* {
* for ($j=0;$j<count($return[Sheet1][$i]);$j++)
* {
* echo $return[Sheet1][$i][$j]."|";
* }
* echo "<br>";
* }
* ?>
* < ?
* require "excel_class.php";
* Read_Excel_File("Book1.xls",$return);
* Create_Excel_File("ddd.xls",$return[Sheet1]);
* ?>
*/
define(’ABC_CRITICAL’, 0);
define(’ABC_ERROR’, [...]


I use frequently some PHP function

Before makes php the project development, uses frequently some functions, reorganize now, shares together with everybody

?View Code PHP< ?php
class function_class{
/**
* Get IP
*
* @return IP
*/
function GetIP() {
if ($_SERVER["HTTP_X_FORWARDED_FOR"]){
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else if ($_SERVER["HTTP_CLIENT_IP"]){
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
else if ($_SERVER["REMOTE_ADDR"]){
$ip = $_SERVER["REMOTE_ADDR"];
}
else if (getenv("HTTP_X_FORWARDED_FOR")){
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
else if (getenv("HTTP_CLIENT_IP")){
$ip = getenv("HTTP_CLIENT_IP");
}
else if (getenv("REMOTE_ADDR")){
$ip = getenv("REMOTE_ADDR");
}
else{
$ip = "Unknown";
}
return [...]


MYSQL limit Optimization-2

The MYSQL optimization is very important. Other most commonly used also most need to optimize are limit. mysql limit has brought enormous convenient to the paging, but the data quantity one is big, the limit performance suddenly drops.
Similarly takes 10 data
select * from temp limit 10000,10
and
select * from temp limit 0,10
It is not a quantity rank.
Now [...]