Category

PHP As Is

28 OCT

Backup of MySQL database with a PHP script

Sometimes you need to make a mysqldump backup without having SSH access or PHPMyAdmin. It can be done with PHP by means of SHOW TABLES/SHOW CREATE TABLE mysql queries. Below is an improved solution proposed here.

Improvements:

  • Got rid of memory_limit – writing to file on every iteration
  • gzip support – you don’t have to download huge uncompressed .sql
  • PHP notice fixed
  • added IF EXISTS to DROP TABLE
  • ereg_replase -> str_replace
  • added set_time_limit(0) to work with large DB’s

In order to make a dump:

Read more



17 FEB

Elance PHP5 code test (with answers)

Here is the list of problems with correct answers for Elance PHP5 Code Test:

1. recursive xml traversal:

 
function ReadXml($xmlstr)
{
    static $res = '';
    $xml = new SimpleXMLElement($xmlstr);
   
    if(count($xml->children()))
    {
        $res .= $xml->getName().PHP_EOL;
        foreach($xml->children() as $child)
        {
            ReadXml($child->asXML());
        }
    }
    else
    {
        $res .= $xml->getName().': '.(string)$xml.PHP_EOL;
    }
   
    return $res;
}
 

Read more