Advertisement
Guest User

Untitled

a guest
Aug 4th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. <?php
  2. //exit(); //Comment this line to have this scripta actually DO anything
  3. //Obviously you'll have to secure access to this script (USING IIS or Apache HTTP authentication)
  4. $host = $_SERVER['argv'][1];
  5. $user = $_SERVER['argv'][2];
  6. $pass = $_SERVER['argv'][3];
  7. $dbname = $_SERVER['argv'][4];
  8.  
  9. connect($host,$user,$pass,$dbname);
  10. echo "Connected\n";
  11. $sql = array();
  12. $sql['list tables'] = '
  13. SELECT TABLE_SCHEMA,TABLE_NAME, OBJECTPROPERTY(object_id(TABLE_NAME), N\'IsUserTable\') AS type
  14. FROM INFORMATION_SCHEMA.TABLES';
  15.  
  16. echo "GETTINGOBJECT\n";
  17. $tables = getObjects($sql['list tables']);
  18. var_dump($tables);
  19. echo "GETTINGOBJECT DONE\n";
  20. header('content-type: text/plain');
  21.  
  22.  
  23. echo "SIMPLEXML DONE\n";
  24. foreach($tables as $table) {
  25. if ($_SERVER['argv'][5] && $_SERVER['argv'][5] != $table->TABLE_NAME)
  26. continue;
  27. $document = new SimpleXMLElement('<table></table>');
  28. echo "GETARRAY\n";
  29. $dump = getArray('SELECT * FROM '.$table->TABLE_SCHEMA.'.'.$table->TABLE_NAME);
  30. echo "GETARRAY DONE\n";
  31.  
  32. $newTable = $document->tables[0]->addChild('table');
  33. $newTable->addAttribute('name',$table->TABLE_NAME);
  34. foreach($dump as $dumpRow) {
  35. $newRow = $newTable->addChild('row');
  36. foreach($dumpRow as $field=>$value) {
  37. $safe_value = preg_replace('/&(?!\w+;)/', '&', $value);
  38. $newRow->addChild($field,$safe_value);
  39. }
  40. }
  41. echo "$filename\n";
  42. $filename = 'bdd/'.$dbname.'-'.$table->TABLE_NAME;
  43. file_put_contents($filename, $document->asXML());
  44. echo "done\n";
  45. }
  46. echo "ASXML DONE\n";
  47.  
  48.  
  49. function connect($host,$user,$pass,$dbname)
  50. {
  51. mssql_connect($host,$user,$pass);
  52. mssql_select_db($dbname);
  53. var_dump(mssql_get_last_message());
  54. }
  55.  
  56.  
  57. /**
  58. * Get the database results as a object array
  59. * @param $query string SQL Query
  60. */
  61. function getObjects($query)
  62. {
  63. $res = mssql_query($query);
  64. if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
  65. return array();
  66. }
  67. $rows = array();
  68. while($row = mssql_fetch_object($res)) {
  69. $rows[] = $row;
  70. }
  71. return $rows;
  72. }
  73.  
  74. /**
  75. * Get the database results as an array
  76. * @param $query string SQL Query
  77. */
  78. function getArray($query)
  79. {
  80. $res = mssql_query($query);
  81. if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
  82. return array();
  83. }
  84. $rows = array();
  85. while($row = mssql_fetch_assoc($res)) {
  86. $rows[] = $row;
  87. }
  88. return $rows;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement