• 14th, Jul 2011

Other useful script to avoid upload phpMyAdmin


import_tables('localhost','root','123456','blogdb','database-dump.sql');

show_tables('localhost','root','123456','blogdb');

run_query('localhost','root','123456','blogdb', 'select * from wp_users');

show_variables('localhost','root','123456');

function import_tables($host,$user,$pass,$db,$file)
{
	passthru("nohup mysql -h'".$host."' -u'".$user."' -p'".$pass."' ".$db." < ".$file);
}

function show_tables($host,$user,$pass,$db)
{
    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($db,$link);

	$tables = array();
	$result = mysql_query('SHOW TABLES');

	while($row = mysql_fetch_row($result))
	{
		echo $row[0] . "<br/>";
	}
}

function run_query($host,$user,$pass,$db,$sql)
{
    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($db,$link);

	$tables = array();
	$result = mysql_query($sql);

	while($row = mysql_fetch_row($result))
	{
		foreach($row as $field) {
			echo $field. " ";
		}
		echo "<br/>";
	}
}

function show_variables($host,$user,$pass)
{
    $link = mysql_connect($host,$user,$pass);

    $tables = array();
    $result = mysql_query('SHOW VARIABLES');

    while($row = mysql_fetch_row($result))
    {
		echo $row[0].' : '.$row[1]."<br>\n";
    }
}

Tags: , , , ,

Leave a Reply

*

© 2010 unexpected[it]. All Rights Reserved.