Sponsored Content
Top Forums Web Development Confused maybe about MySQL Dump & PHP Post 302320913 by jzacsh on Friday 29th of May 2009 09:45:11 AM
Old 05-29-2009
Question Confused maybe about MySQL Dump & PHP

Hello. the purpose of my efforts right now are to get a larger script of mine (which the admin told me he'd put into cron for me) to properly back-up my MySQL database. To test out the sql back-up part (before getting the whole script into cron, and having it not work) I wanted to test it. So here's what I did:

PHP file to do my testing (on the live server)
Code:
<?php

$test = shell_exec('echo $SHELL');
echo "<pre>$test</pre>";

$output = shell_exec('sh ./sqlBack.sh');
echo "<pre>$output</pre>";
?>

Script being called by the PHP
Code:
#!/usr/local/bin/bash

# MYSQL BACKUP:
sql_bDir="./sql_backups/" #LOCATION FOR SQL BACKUPS TO LAND
sql_bName=SqlBackup_$(date "+%A")

echo "The Shopping Cart's database backup will be in $sql_bDir and will be named $sql_bName" #NOTICE OF DATABASE BACKUP
mysqldump -uNAME -pPASS --opt DBASENAME > $sql_bDir$sql_bName.tgz

just for testing, both these files were set to 777 on the server. The output from the PHP file looks just as it should, but then I find the ./sql_backups/ directory empty. I tried the username, password and database of the last line of that script in both capital letters and lower case (read somewhere that capitals works better.. anyways). I'm not experienced with php/mysql.. I found the syntax for that mysqldump line in an article.

Thanks in advance for all your help!!
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Linux/Unix/PHP/MySQL & servers?

Hello everyone! First I would like to say that I am very glad that I found this forum, and by some of the posts I have viewed, I see that I can learn a lot from you all! Secondly, I know next to nothing about Linux/Unix (gotta learn sometime right?) and need some assistance. I am a... (5 Replies)
Discussion started by: kolton
5 Replies

2. UNIX for Dummies Questions & Answers

PHP & Apache & MySQL install how-to ?

how do i install php & mysql with apache on suse linux ??? apache was installed and configured when i installed linux. all its files are in different folders. e.g http files in usr/local/httpd/htdocs/ and its configs are in etc/httpd/ so how do i install php and get it to work with apache and... (4 Replies)
Discussion started by: perleo
4 Replies

3. Shell Programming and Scripting

PHP & MySQL: sort desending and print

How do i get php to sort the times in a table and print order desending. eg: in the table i have: 02:60.00 02:70.00 02:20.00 02:50.00 in that order in a table how do i get php & mysql to print... (1 Reply)
Discussion started by: perleo
1 Replies

4. Shell Programming and Scripting

restore mysql dump file in many remote servers?

Hi all, I want to restore DB file in many mysql servers, i already using script for sending the dumpfile in all servers, but it's just annoying if i have to restore the dumpfile in all servers, i want just execute 1 script, and will restore in all remote mysql servers. I make script but not... (2 Replies)
Discussion started by: blesets
2 Replies

5. Shell Programming and Scripting

how to break mysql dump sql file

Hi folks I have mysql dump which having insert queries, i want to break that file when 10 complete "INSERTS" lines so extract that line and store in 1.sql and 2.sql and for next 10 insert lines. pls guide me how can i do that. Regards, Bash (2 Replies)
Discussion started by: learnbash
2 Replies

6. Web Development

[php] webpage with login & mysql-db

Hi all, What I was looking for before was a multi-user password manager, web-based! The offer of free or cheap tools of this kind is very pover. Or they are too complex (or too expensive) I'm not a web programmer but I now decided to set up a (php) website with login and based on this login... (1 Reply)
Discussion started by: thibautp
1 Replies

7. Shell Programming and Scripting

PHP read large string & split in multidimensional arrays & assign fieldnames & write into MYSQL

Hi, I hope the title does not scare people to look into this thread but it describes roughly what I'm trying to do. I need a solution in PHP. I'm a programming beginner, so it might be that the approach to solve this, might be easier to solve with an other approach of someone else, so if you... (0 Replies)
Discussion started by: lowmaster
0 Replies

8. Shell Programming and Scripting

Can't add variable to file name in mySQL dump script

I have a script (below) which works ok, but I have tried to modify it as I want to keep the older files for a restore if needed. I have tried adding a date suffix to the newly created files (second lump of code), but it doesn't seem to work. I get the error: $SOURCEDIR/p1db_$DATEVAR.sql:... (3 Replies)
Discussion started by: ojobson
3 Replies

9. Shell Programming and Scripting

Create mysql database with bash script - confused

Hi, i have the following: db="create database xxx;GRANT ALL PRIVILEGES ON xxx.* TO user@localhost IDENTIFIED BY 'password';FLUSH PRIVILEGES;quit;" mysql -u root -p$mysql_pass -e "$db" I don't understand why this is failing, it works fine when run from cmd but when is run in a bash script,... (1 Reply)
Discussion started by: ktm
1 Replies
MYSQL_LIST_TABLES(3)							 1						      MYSQL_LIST_TABLES(3)

mysql_list_tables - List tables in a MySQL database

SYNOPSIS
Warning This function was deprecated in PHP 4.3.0, and will be removed in the future, along with the entirety of the original MySQL exten- sion. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: oSQL Query: SHOW TABLES FROM sometable resource mysql_list_tables (string $database, [resource $link_identifier = NULL]) DESCRIPTION
Retrieves a list of table names from a MySQL database. This function is deprecated. It is preferable to use mysql_query(3) to issue an SQL SHOW TABLES [FROM db_name] [LIKE 'pattern'] statement instead. o $database - The name of the database o $ link_identifier -The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect(3) is assumed. If no such link is found, it will try to create one as if mysql_connect(3) was called with no arguments. If no connection is found or established, an E_WARNING level error is generated. A result pointer resource on success or FALSE on failure. Use the mysql_tablename(3) function to traverse this result pointer, or any function for result tables, such as mysql_fetch_array(3). +--------+-----------------------------------+ |Version | | | | | | | Description | | | | +--------+-----------------------------------+ | 4.3.7 | | | | | | | This function became deprecated. | | | | +--------+-----------------------------------+ Example #1 mysql_list_tables(3) alternative example <?php $dbname = 'mysql_dbname'; if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) { echo 'Could not connect to mysql'; exit; } $sql = "SHOW TABLES FROM $dbname"; $result = mysql_query($sql); if (!$result) { echo "DB Error, could not list tables "; echo 'MySQL Error: ' . mysql_error(); exit; } while ($row = mysql_fetch_row($result)) { echo "Table: {$row[0]} "; } mysql_free_result($result); ?> Note For backward compatibility, the following deprecated alias may be used: mysql_listtables(3) mysql_list_dbs(3), mysql_tablename(3). PHP Documentation Group MYSQL_LIST_TABLES(3)
All times are GMT -4. The time now is 04:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy