Re: You guys will find this easy...

From: Date: Wed, 06 Dec 2000 10:52:15 +0000
Subject: Re: You guys will find this easy...
Groups: php.general 
Request: Send a blank email to php-general+get-28706@lists.php.net to get a copy of this message
"Joe Stump" <joe@earth.care2.com>, on the subject of 'Re: [PHP] You guys will find this easy...', is quoted as: >Well you will want to combine bash and php - so here goes! Not neccesarily.. =) At least I didn't..of course, I've got mysql support compiled in php. So, I guess that's a prerequisite for this. Anyhow, here goes... first you'll need the sql file to create the database table, or at least I did..I'm mostly supplying this as a reference so you'll know the environment I was working with. thesql.sql: DROP table user_info; CREATE TABLE user_info ( ID INT, website VARCHAR (100), email VARCHAR (25)); then i used a couple of files with the format you described as near as I could figure it out. here's an example... mccrorey.user: 42 mccrorey@optushome.com.au http://clanmecha.sourceforge.net then, of course, there's that script.. =) Like I say, i used built in php functionality. (btw, i do php on the command line on this box, if you don't, just chop off the top line) fop.php: #!/usr/local/bin/php <? $db_host = "localhost"; /* the machine running mysql */ $db_user = "someuser"; /* the user you'll connect as */ $db_pword = ""; /* the password for the specified user */ $db_table = "user_info"; /* the table you'll be inserting into */ $db_database = "users"; /* the database you want to use */ /* connect to the database or die screaming =) */ $db = @mysql_connect($db_host, $db_user, $db_pword) or die("bloody bloody bloody!\n"); mysql_select_db($db_database, $db); /* specify what directory we'll be using */ $d = dir("./"); while($entry=$d->read()) { if(eregi("user", $entry)) { print $entry."\n"; $fc = fopen($entry, "r") or die("bloody bloody bloody!\n"); for($i = 0; !feof ($fc); $i++) { $buffer = fgets($fc, 1042); $buff_array[$i] = $buffer; } fclose ($fc); mysql_query("insert into $db_table values ('$buff_array[0]', '$buff_array[1]', '$buff_array[2]')"); } } $d->close; mysql_close(); ?> so, there ya go. PLEASE let me know if this helps or if there are any problems!! Cheers, Brad McCrorey brand alchemist dingo blue http://dingoblue.com.au work e-mail:brad.mccrorey@dingoblue.com.au home e-mail:mccrorey@optushome.com.au

« previous php.general (#28706) next »