Offtopic Juegos, temas personales, trabajo, aficiones, trucos, etc


 
Herramientas
  #1  
Viejo 27/08/11, 00:31:01
Avatar de david.te
david.te david.te no está en línea
Miembro del foro
Mensajes: 255
 
Fecha de registro: jul 2011
Mensajes: 255
Mencionado: 5 comentarios
Tagged: 0 hilos
Exportar datos sql a xml y guardarlo en un host

Hola!
Estoy intentando hacer, y por más que busco no encuentro, como poder exportar los datos de mi base de datos sql a xml, y poder guardarlo en mi host, automáticamente, y que se actualice cada cierto tiempo.
He buscado y solo he encontrado esto, y no se muy bien para que sirve:

<?php
// database constants
// make sure the information is correct
define("DB_SERVER", "localhost");
define("DB_USER", "root");
define("DB_PASS", "password");
define("DB_NAME", "tutorials");

// connection to the database
$dbhandle = mysql_connect(DB_SERVER, DB_USER, DB_PASS)
or die("Unable to connect to MySQL");

// select a database to work with
$selected = mysql_select_db(DB_NAME, $dbhandle)
or die("Could not select examples");

// return all available tables
$result_tbl = mysql_query( "SHOW TABLES FROM ".DB_NAME, $dbhandle );

$tables = array();
while ($row = mysql_fetch_row($result_tbl)) {
$tables[] = $row[0];
}

$output = "<?xml version=\"1.0\" ?>\n";
$output .= "<schema>";

// iterate over each table and return the fields for each table
foreach ( $tables as $table ) {
$output .= "<table name=\"$table\">";
$result_fld = mysql_query( "SHOW FIELDS FROM ".$table, $dbhandle );

while( $row1 = mysql_fetch_row($result_fld) ) {
$output .= "<field name=\"$row1[0]\" type=\"$row1[1]\"";
$output .= ($row1[3] == "PRI") ? " primary_key=\"yes\" />" : " />";
}

$output .= "</table>";
}

$output .= "</schema>";

// tell the browser what kind of file is come in
header("Content-type: text/xml");
// print out XML that describes the schema
echo $output;

// close the connection
mysql_close($dbhandle);
?>
Responder Con Cita


Respuesta

Estás aquí
Regresar   HTCMania > Club HTCMania > Offtopic

Herramientas

Reglas de Mensajes
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Las caritas están On
Código [IMG] está On
Código HTML está Off

Saltar a Foro



Hora actual: 19:35:02 (GMT +2)

Cookies settings
Powered by vBulletin™
Copyright © vBulletin Solutions, Inc. All rights reserved.
 
HTCMania: líderes desde el 2007