Skip to main content

Posts

Showing posts from February, 2014

Backup Your MySQL Database Using PHP

One of the most important tasks any developer needs to do often is back up their MySQL database. In many cases, the database is what drives most of the site. While most web hosts do a daily backup of a customer's database, relying on them to make backups and provide them at no cost is risky to say the least. That's why I've created a database backup function that I can call whenever I want -- including nightly CRONs. The PHP & MySQL Code backup_tables ( 'localhost' , 'username' , 'password' , 'blog' ) ; /* backup the db OR just a table */ function backup_tables ( $host , $user , $pass , $name , $tables = '*' ) { $link = mysql_connect ( $host , $user , $pass ) ; mysql_select_db ( $name , $link ) ; //get all of the tables if ( $tables == '*' ) { $tables = array ( ) ; $result = mysql_query ( 'SHOW TABLES' ) ; while ( $row = mysql_fetch_row ( $result ) ) { $...

Send Files via FTP Using PHP

Sending files to a server via FTP is an essential ability of any web developer or designer. Of course, we all use glossy FTP clients like WS_FTP and FireFTP, but what about FTP automation? You can use PHP to FTP files from one server to another. Let me show you how.       // set_time_limit(0); $connection = ftp_connect ( "easycms.in" ) ; $login = ftp_login ( $connection , "admin@easycms.in" , "hl0809@" ) ; if ( ! $connection ) { die ( 'Connection attempt failed!' ) ; } else { echo "connection passed" ; } if ( ! $login ) { die ( 'Login attempt failed!' ) ; } else { echo "login passed" ; } ftp_pasv ( $connection , true ) ; < p> $source = "adv_banner.jpg" ; $dest = "recipe_image/adv_banner.jpg...