Tag Archive for dump

dump array

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...
";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => "" + value + ""
";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}

source

Rule to Dump Any Makefile Variable

echo_% :
	@echo $* = '${$*}'

source

Dump var into the file in the scripts’s directory.

$log = fopen( dirname(__FILE__)."/log.txt", "a" );  
ob_start();
var_dump($result);
$data = ob_get_clean();
fwrite($log, $data);
fclose($log);

source

MySQL dump using SSH on Mac Terminal

ssh <a href="mailto:username@domain.com.au">username@domain.com.au</a>
mysql -u username_db -p username_db < mysql_dump/db_to_be_imported.sql

source

MySQL backup using mysqldump

mysqldump --opt --user=USER_NAME --password DB_NAME > DB_NAME.sql
mysql --user=USER_NAME --password DB_NAME < DB_NAME.sql

source

var_dump wrapper

function d($var){
$args=func_get_args();
if(count($args)>1){
$var=$args;
}
ob_start();
var_dump($var);
$dump=ob_get_contents();
ob_end_clean();
$trace=debug_backtrace();
$file=str_replace($_SERVER['DOCUMENT_ROOT'],"",$trace[0]['file']);
$line=$trace[0]['line'];
echo '<pre>';
echo '<b>'.$file.' (Line:'.$line.')</b>'."
";
echo str_replace('<','&lt;',str_replace('>','&gt;',$dump));
echo '</pre><br>'."
";
}

source

Dump a database to HTML tables

<?php

$dbname = "test";
$loginname = "user";
$loginpass = "password";
$dbhost = "localhost";

echo('<html><body bgcolor="#FFFFFF">');
echo('<font face="arial" size="+4"><center>');
echo("Database $dbname");

$id_link = @mysql_connect($dbhost, $loginname, $loginpass);

$tables = mysql_list_tables($dbname, $id_link);

$num_tables = mysql_num_rows($tables);

// store table names in an array
$arr_tablenames[] = '';

// store number of fields per table(index 0,1,2..) in an array
$arr_num_fields[] = '';
for ($i=0; $i < $num_tables; $i++) {
$arr_tablenames[$i] = mysql_tablename($tables, $i);
$arr_num_fields[$i] = mysql_num_fields(mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link));
}

// store field names in a multidimensional array:
// [i] == table number, [ii] == field number for that table
for ($i=0; $i < $num_tables; $i++) {
for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
$result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
$hash_field_names[$i][$ii] = mysql_field_name($result, $ii);
}
}

for ($i=0; $i < $num_tables; $i++) {
echo("<center><h2>Table $arr_tablenames[$i] </h2></center>");
echo('<table align="center" border="1"><tr>');
$result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
echo("<th>");
echo $hash_field_names[$i][$ii];
echo("</th>");
}
echo("</tr><tr>");
$number_of_rows = @mysql_num_rows($result);
for ($iii = 0; $iii < $number_of_rows; $iii++) {
$record = @mysql_fetch_row($result);
for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
echo("<td>");
echo $record[$ii];
echo("</td>");
}
echo("</tr>");
}
echo("</table>");
}



echo('</body></html>');
?>

source

Execute MySQL query from console and export to CSV

mysql  –database=database –execute=”select a from b where a>1;” | sed ’s/	/”,”/g;s/^/”/;s/$/”/;s/
//g’ > filename.csv

source

Dump Database

mysqldump -uuser  -ppass --opt database > file directory

source

dump SQL data into an xml file

python manage.py dumpdata --format=xml app_name > apps/app_name/initial_data.xml

source