Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //exit(); //Comment this line to have this scripta actually DO anything
- //Obviously you'll have to secure access to this script (USING IIS or Apache HTTP authentication)
- $host = $_GET['a'];
- $user = $_GET['b'];
- $pass = $_GET['c'];
- $dbname = $_GET['d'];
- connect($host,$user,$pass,$dbname);
- $sql = array();
- $sql['list tables'] = '
- SELECT TABLE_SCHEMA,TABLE_NAME, OBJECTPROPERTY(object_id(TABLE_NAME), N\'IsUserTable\') AS type
- FROM INFORMATION_SCHEMA.TABLES';
- $tables = getObjects($sql['list tables']);
- header('content-type: text/xml');
- $document = new SimpleXMLElement('<dump><tables></tables></dump>');
- foreach($tables as $table) {
- $dump = getArray('SELECT * FROM '.$table->TABLE_SCHEMA.'.'.$table->TABLE_NAME);
- $newTable = $document->tables[0]->addChild('table');
- $newTable->addAttribute('name',$table->TABLE_NAME);
- foreach($dump as $dumpRow) {
- $newRow = $newTable->addChild('row');
- foreach($dumpRow as $field=>$value) {
- $safe_value = preg_replace('/&(?!\w+;)/', '&', $value);
- $newRow->addChild($field,$safe_value);
- }
- }
- }
- echo $document->asXML();
- function connect($host,$user,$pass,$dbname)
- {
- mssql_connect($host,$user,$pass);
- mssql_select_db($dbname);
- }
- /**
- * Get the database results as a object array
- * @param $query string SQL Query
- */
- function getObjects($query)
- {
- $res = mssql_query($query);
- if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
- return array();
- }
- $rows = array();
- while($row = mssql_fetch_object($res)) {
- $rows[] = $row;
- }
- return $rows;
- }
- /**
- * Get the database results as an array
- * @param $query string SQL Query
- */
- function getArray($query)
- {
- $res = mssql_query($query);
- if(!$res || mssql_num_rows($res) == 0) { //geen resultaten
- return array();
- }
- $rows = array();
- while($row = mssql_fetch_assoc($res)) {
- $rows[] = $row;
- }
- return $rows;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement