hola es que tengo este codigo para guardar la base de datos
proceso_respaldar_bd.php
Código PHP:
Ver original<?php
require_once("includes/db_connect.php");
require_once("cron/sql_dump.php");
$server = new server();
$nombre_base = 'nombre';
$nombre2 = 'funciones/' . $nombre_base;
$nombre_archivo = $nombre2 . '-' . date('Y-m-d-H-i-s') . '.bak';
// Hacer el dump
$dump = new MySQLDump();
$sql = $dump->dumpDatabase( $nombre_base );
// Abrir y guardar el dump
$archivo = fopen($nombre_archivo, 'w');
?>
sql_dump.php
Código PHP:
Ver original<?php
/**
* Dump data from MySQL database
*
* $dump = new MySQLDump();
* print $dump->dumpDatabase("mydb");
*
*/
class MySQLDump {
/**
* Dump data and structure from MySQL database
*
* @param string $database
* @return string
*/
function dumpDatabase($database) {
$structure = '';
$data = '';
// Connect to database
// Get all table names from database
$c = 0;
//echo mysql_tablename($result, $x) . '<br>';
//continue;
$c++;
}
}
// List tables
$dump = '';
for ($y = 0; $y < count($arr_tables); $y++){
// DB Table name
$table = $arr_tables[$y];
// Structure Header
$structure .= "-- \n";
$structure .= "-- Table structure for table `{$table}` \n";
$structure .= "-- \n\n";
// Dump Structure
$structure .= "DROP TABLE IF EXISTS `{$table}`; \n";
$structure .= "CREATE TABLE `{$table}` (\n";
$structure .= " `{$row->Field}` {$row->Type}";
$structure .= (!empty($row->Default)) ?
" DEFAULT '{$row->Default}'" : false; $structure .= ($row->Null != "YES") ? " NOT NULL" : false;
$structure .= (!empty($row->Extra)) ?
" {$row->Extra}" : false; $structure .= ",\n";
}
// Save all Column Indexes in array
// unset($index);
$index = '';
if (($row->Key_name == 'PRIMARY') AND ($row->Index_type == 'BTREE')) {
$index['PRIMARY'][$row->Key_name] = $row->Column_name;
}
if (($row->Key_name != 'PRIMARY') AND ($row->Non_unique == '0') AND ($row->Index_type == 'BTREE')) {
$index['UNIQUE'][$row->Key_name] = $row->Column_name;
}
if (($row->Key_name != 'PRIMARY') AND ($row->Non_unique == '1') AND ($row->Index_type == 'BTREE')) {
$index['INDEX'][$row->Key_name] = $row->Column_name;
}
if (($row->Key_name != 'PRIMARY') AND ($row->Non_unique == '1') AND ($row->Index_type == 'FULLTEXT')) {
$index['FULLTEXT'][$row->Key_name] = $row->Column_name;
}
}
// Return all Column Indexes of array
foreach ($index as $xy => $columns) {
$structure .= ",\n";
$c = 0;
foreach ($columns as $column_key => $column_name) {
$c++;
$structure .= ($xy == "PRIMARY") ? " PRIMARY KEY (`{$column_name}`)" : false;
$structure .= ($xy == "UNIQUE") ? " UNIQUE KEY `{$column_key}` (`{$column_name}`)" : false;
$structure .= ($xy == "INDEX") ? " KEY `{$column_key}` (`{$column_name}`)" : false;
$structure .= ($xy == "FULLTEXT") ? " FULLTEXT `{$column_key}` (`{$column_name}`)" : false;
$structure .= ($c < (count($index[$xy]))) ?
",\n" : false;
}
}
}
$structure .= "\n);\n\n";
// Header
$structure .= "-- \n";
$structure .= "-- Dumping data for table `$table` \n";
$structure .= "-- \n\n";
// Dump data
$data='';
for ($i = 0; $i < $num_rows; $i++) {
$data .= "INSERT INTO `$table` (";
// Field names
for ($x = 0; $x < $num_fields; $x++) {
$data .= "`{$field_name}`";
$data .= ($x < ($num_fields - 1)) ? ", " : false;
}
$data .= ") VALUES (";
// Values
for ($x = 0; $x < $num_fields; $x++) {
$data .= ($x < ($num_fields - 1)) ? ", " : false;
}
$data.= ");\n";
}
$data.= "\n";
$dump .= $structure . $data;
$dump .= "-- --------------------------------------------------------\n\n";
}
return $dump;
}
}
}
?>
pero tengo un problema que me funciona en un servidor en windows con appserver
pero en un servidor linux me tira eror
Warning: fopen(backop/DB-2011-07-11-20-40-00.bak) [function.fopen]: failed to open stream: Permission denied in /var/www/prueba/cron/proceso_respaldar_bd.php on line 14
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/prueba/cron/proceso_respaldar_bd.php on line 15
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/prueba/cron/proceso_respaldar_bd.php on line 16