Re: Newbie Question: mysqldump via PHP

From: Date: Tue, 04 Sep 2001 20:21:15 +0000
Subject: Re: Newbie Question: mysqldump via PHP
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-65939@lists.php.net to get a copy of this message
Hi Jason No, but I have taken the output from $xarray ... ------------------------------------------------------ $result = exec("mysqldump -umyname --password=mypassword tablename >db.dump",$xarray,$status); echo "status[$status]<br>"; $count = count($xarray); echo "<p>result of dump[$result] status[$status]<br>"; for($j=0; $j<$count;$j++) echo "$j: $xarray[$j]<p>"; ------------------------------------------------------ which, according to the PHP exec command, is supposed to return all the output from the mysqldump command. The resulting output is not what I expected. Instead of the database dump, all I get is what appears to be the mysqldump help information. I'm confused! Output of dump follows SORRY FOR the length of this.... ================================================================ result of dump[net_buffer_length current value: 1047551] status[127] 0: /usr/bin/mysqldump Ver 8.14 Distrib 3.23.40, for pc-linux-gnu (i686) 1: By Igor Romanenko, Monty, Jani & Sinisa 2: This software comes with ABSOLUTELY NO WARRANTY. This is free software, 3: and you are welcome to modify and redistribute it under the GPL license 4: 5: Dumping definition and data mysql database or table 6: Usage: /usr/bin/mysqldump [OPTIONS] database [tables] 7: OR /usr/bin/mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] 8: OR /usr/bin/mysqldump [OPTIONS] --all-databases [OPTIONS] 9: 10: -A, --all-databases Dump all the databases. This will be same as 11: --databases with all databases selected. 12: -a, --all Include all MySQL specific create options. 13: -#, --debug=... Output debug log. Often this is 'd:t:o,filename`. 14: --character-sets-dir=... 15: Directory where character sets are 16: -?, --help Display this help message and exit. 17: -B, --databases To dump several databases. Note the difference in 18: usage; In this case no tables are given. All name 19: arguments are regarded as databasenames. 20: 'USE db_name;' will be included in the output 21: -c, --complete-insert Use complete insert statements. 22: -C, --compress Use compression in server/client protocol. 23: --default-character-set=... 24: Set the default character set 25: -e, --extended-insert Allows utilization of the new, much faster 26: INSERT syntax. 27: --add-drop-table Add a 'drop table' before each create. 28: --add-locks Add locks around insert statements. 29: --allow-keywords Allow creation of column names that are keywords. 30: --delayed-insert Insert rows with INSERT DELAYED. 31: -F, --flush-logs Flush logs file in server before starting dump. 32: -f, --force Continue even if we get an sql-error. 33: -h, --host=... Connect to host. 34: -l, --lock-tables Lock all tables for read. 35: -n, --no-create-db 'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' 36: will not be put in the output. The above line will 37: be added otherwise, if --databases or 38: --all-databases option was given. 39: -t, --no-create-info Don't write table creation info. 40: -d, --no-data No row information. 41: -O, --set-variable var=option 42: give a variable a value. --help lists variables 43: --opt Same as --add-drop-table --add-locks --all 44: --extended-insert --quick --lock-tables 45: -p, --password[=...] Password to use when connecting to server. 46: If password is not given it's solicited on the tty. 47: 48: -P, --port=... Port number to use for connection. 49: -q, --quick Don't buffer query, dump directly to stdout. 50: -Q, --quote-names Quote table and column names with ` 51: -r, --result-file=... Direct output to a given file. This option should be 52: used in MSDOS, because it prevents new line '\n' 53: from being converted to '\n\r' (newline + carriage 54: return). 55: -S, --socket=... Socket file to use for connection. 56: --tables Overrides option --databases (-B). 57: -T, --tab=... Creates tab separated textfile for each table to 58: given path. (creates .sql and .txt files). 59: NOTE: This only works if mysqldump is run on 60: the same machine as the mysqld daemon. 61: -u, --user=# User for login if not current user. 62: -v, --verbose Print info about the various stages. 63: -V, --version Output version information and exit. 64: -w, --where= dump only selected records; QUOTES mandatory! 65: EXAMPLES: "--where=user='jimf'" "-wuserid>1" "-wuserid<1" 66: Use -T (--tab=...) with --fields-... 67: --fields-terminated-by=... 68: Fields in the textfile are terminated by ... 69: --fields-enclosed-by=... 70: Fields in the importfile are enclosed by ... 71: --fields-optionally-enclosed-by=... 72: Fields in the i.file are opt. enclosed by ... 73: --fields-escaped-by=... 74: Fields in the i.file are escaped by ... 75: --lines-terminated-by=... 76: Lines in the i.file are terminated by ... 77: 78: Default options are read from the following files in the given order: 79: /etc/my.cnf /var/lib/mysql/my.cnf ~/.my.cnf 80: The following groups are read: mysqldump client 81: The following options may be given as the first argument: 82: --print-defaults Print the program argument list and exit 83: --no-defaults Don't read default options from any options file 84: --defaults-file=# Only read default options from the given file # 85: --defaults-extra-file=# Read this file after the global files are read 86: 87: Possible variables for option --set-variable (-O) are: 88: max_allowed_packet current value: 25165824 89: net_buffer_length current value: 1047551 ================================================================ Thanks again! Tony Jason Bell wrote: > > Have you tried storing the mysqldump output to a string and then using PHP > to open a file, dump the string into the file, and then close the file? > > Might work that way... > > ----- Original Message ----- > From: "Tony Frasketi" <webmaster@spacecovers.com> > To: "Sam Masiello" <smasiello@synacor.com> > Cc: <php-general@lists.php.net> > Sent: Tuesday, September 04, 2001 12:39 PM > Subject: Re: [PHP] Newbie Question: mysqldump via PHP > > > Hi Sam > > Thanks to suggestions from jason, Alexander, and yourself I tried the > > unix which command and found that mysqldump was located at... > > > > /usr/bin/ directory > > > > And I changed my exec command to include this directory but alas, the > > results were the same. > > > > Is it possible that the mysqldump command cannot be run from PHP under > > user nobody? > > > > Still appreciative of any other ideas I can try! > > Tony F. > > > > Sam Masiello wrote: > > > > > > Have you tried putting in the fully qualified pathname to the mysqldump > > > executable? > > > > > > /usr/somepath/mysqldump <rest of your command here> > > > > > > HTH > > > > > > Sam Masiello > > > Software Quality Assurance Engineer > > > Synacor > > > (716) 853-1362 X289 > > > smasiello@synacor.com > > > > > > -----Original Message----- > > > From: Tony Frasketi [mailto:webmaster@spacecovers.com] > > > Sent: Tuesday, September 04, 2001 2:28 PM > > > To: Sam Masiello > > > Cc: php-general@lists.php.net > > > Subject: Re: [PHP] Newbie Question: mysqldump via PHP > > > > > > Hi Sam > > > Thanks for the reply. I had the permission set for 777 so that should > > > allow access to the directory for writing from PHP, should it not? > > > > > > Also I tried specifying >/tmp/db.dump in the command and had the tmp > > > directory permission also set for 777 but still get same results. The > > > file get written but it's still set to zero bytes. > > > > > > Any other suggestions would be greatly appreciated. > > > > > > Sam Masiello wrote: > > > > > > > > I would say that you have a permission problem with where PHP is > > > trying > > > > to write the file to. Try outputting the file to /tmp/db.dump and see > > > > if you have the same problem. > > > > > > > > HTH > > > > > > > > Sam Masiello > > > > Software Quality Assurance Engineer > > > > Synacor > > > > (716) 853-1362 X289 > > > > smasiello@synacor.com > > > > > > > > -----Original Message----- > > > > From: Tony Frasketi [mailto:webmaster@spacecovers.com] > > > > Sent: Tuesday, September 04, 2001 1:56 PM > > > > To: php-general@lists.php.net > > > > Subject: [PHP] Newbie Question: mysqldump via PHP > > > > > > > > Hello listers > > > > > > > > I'm trying to implement a mySQL database dump via PHP4 on a unix > > > system > > > > as follows... > > > > > > > > ------------------------------------------------------ > > > > $result = exec("mysqldump -umyname --password=mypassword > > > > tablename >db.dump",$xarray,$status); > > > > echo "status[$status]<br>"; > > > > ------------------------------------------------------ > > > > > > > > I get the following error PHP error message... > > > > > > > > status[127] > > > > > > > > and the file 'db.dump' has been created but it has 0 bytes. > > > > > > > > -rw-r--r-- 1 nobody nobody 0 Sep 4 13:27 db.dump > > > > > > > > Although I can execute the mysqldump program from the unix shell and I > > > > get... > > > > > > > > -rw-r--r-- 1 myname myname 23704 Sep 4 13:18 db.dump > > > > > > > > My questions are... > > > > > > > > 1. Can the mysqldump program be executed via PHP or not and if not > > > > can you please explain why? > > > > > > > > 2. Is there another way of doing this via PHP? > > > > > > > > Thanks in advance > > > > Tony Frasketi > > > > P.S. Please answer direct, since I'm only subscribed to the digest. > > > > > > > > -- > > > > PHP General Mailing List (http://www.php.net/) > > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > > For additional commands, e-mail: php-general-help@lists.php.net > > > > To contact the list administrators, e-mail: > > > php-list-admin@lists.php.net > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > >

« previous php.general (#65939) next »