ACJavascript 12-19-2003, 12:49 AM Okay,
I need to remove a name from a single database...
a .db.
I did this in PERL by putting the whole database in an array and then just using split() module to remove the one listing then wrote the array back to the database.
How can I do the same thing in PHP???
I've been trying to get it for 2 days now Im starting to loose my mind lol
Any help is VERY appreciated!! :D
Spookster 12-19-2003, 01:01 AM You are kidding right? :confused:
You don't need to pull in all the records of the database. In your SQL statement you simply need to delete the record based on your criteria. What kind of database system are you using? MySQL?
ACJavascript 12-19-2003, 01:07 AM Hey spook,
see I am using .dbs
The host my client is using doens't have MYSQL and they can't afford anything else so Im forced to use .dbs.
Its onlyfor newsletters. So I just need to be able to remove one listing to get rid of a email.
Yea I know lol ;)
Paul Jr 12-19-2003, 02:58 AM Originally posted by ACJavascript
The host my client is using doens't have MYSQL and they can't afford anything else so Im forced to use .dbs.
Last I checked MySQL was free... :rolleyes:
ACJavascript 12-19-2003, 06:23 AM MySQL is free,, Hosts are not...
I think I could mabye use a mysql database on one my other servers... Hmm,, I might just do that...
Anyways it would still be good to konw how to remove a line from a database.
DrWeb 12-19-2003, 07:20 PM Originally posted by ACJavascript
MySQL is free,, Hosts are not...
I think I could mabye use a mysql database on one my other servers... Hmm,, I might just do that...
Anyways it would still be good to konw how to remove a line from a database.
have you tried changing hosting company? :D
ACJavascript 12-19-2003, 08:54 PM hahaha,
They have already payed for a years worth on this host and dont want to change LOL....
I am already going to use a MySQL database on my other server for this.... But I still wouldlike to know how to accomplish this.
I found this code in a Mailing List Manager but it deson't work when I try to use it,, andy advice?
$base_file = new csvfile;
$base_file->name=$main_data_file;
$base_file->init();
I didn't add the rest of the script for actual remvoing the line, but I get a error on the new csvfile part.
Any ideas?
DrWeb 12-19-2003, 09:11 PM you need to specify to which host should php connect to, then you need to allow connection to that host, for that username from different hosts then localhost
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, ALTER PRIVILEGES ON * . * TO "_your_username_"@ "www.someserver.net"
ACJavascript 12-19-2003, 09:21 PM Hey DR.
The code I showed was used to remove a listing from a text file.
DrWeb 12-19-2003, 09:28 PM Originally posted by ACJavascript
Hey DR.
The code I showed was used to remove a listing from a text file.
oh :) Damn misunderstanding :)
if you have a cvs file, then you might want to try to split it into array and then either insert into mysql database or work with it and suffer with it as is :)
ACJavascript 12-19-2003, 09:36 PM THey guys code was pretty simple, Didn't use any special codes except for hte cvs thing.
Weird lol
Celtboy 12-19-2003, 09:56 PM what does a standard query to the db look like? I'm not familiar with DBS. If it's a flat file db, Then...
Read in each line into array
delete last element
write array back to file
I'd kinda have to know what exactly you use to access this...and what a dbs file looks like.
ACJavascript 12-19-2003, 09:59 PM Hey celtboy,
Its named this for example:
Test.db
Its like test.txt or a test.dat.
As for whats in it theres 1 email per line.
Somthing@aol.com
Somthing2@aol.com
Somthing3@aol.com
ect...
Your idea is what I was thinking, just not sure out to do it.
In Perl I place it all into a Array then use the module SPLIT to remove the on that equals the query. But I have no clue how to do that in PHP :(
Celtboy 12-19-2003, 11:19 PM Ok, I'll try this really fast, without any error checking, testing, etc....
<?
function delete_line($what_to_delete) {
$lines = file("Test.db");
foreach ($lines as $value) {
$value = ereg_replace("\\r\\n","",$value); // need to remove the newline character...
if ($value == $what_to_delete) {
// do nothing...we just won't write the line back
} else {
$new_array[sizeof($new_array)+1] = $lines;
}
}
$the_file = fopen("Test.db","w");
foreach ($new_array as $line) {
fputs($the_file,$line . "\\r\\n",1024);
}
fclose($the_file);
return;
}
?>
That might work.... ;)
ACJavascript 12-20-2003, 12:47 AM Hey CELTBOY!
THat works except for one thing.
Instead of writting back the actual values it writes them all back as Array...???
It seems to work since when I remove one thers one missing from the count.
So now its just getting the real values back into the database instead of Array.
THANKS ALOT THOUGH I REALLY APPRECIATE IT :D:D:D:D
firepages 12-20-2003, 02:00 AM almost as an aside , explode() is useful sometimes as it removes the string you explode by..
eg this would remove all instances of joe@blogs.net from a given file...
<?
$file='emails.txt';
$remove="joe@blogs.net\n"; /*or \r\n for win32*/
$replaced = implode( '' , explode( $remove , implode( '', file($file) ) ) ) ;
echo $replaced;
/*you still have to resave it*/
?>
firepages 12-20-2003, 02:03 AM also ....to those who thought *SQL was a better option , well it is , but once that has been pointed out there is no need to continue pointing it out , or variances of ... either answer the question or ignore it ;)
ACJavascript 12-20-2003, 03:11 AM THANKS SO MUCH firepages!!!! :D
That worked perfectly :thumbsup:
Very cool.
Celtboy 12-20-2003, 07:27 AM SURE fp....do it the EASY way......wussie... ;)
LOL. GJ. That's why I like to plan my code, rather than just type it really fast, but you're right. Had I been thinking...(duh), i'd have done it that way.
So pleh. :D :thumbsup:
firepages 12-20-2003, 07:49 AM lol@Celt , well normally I would say bah! to the code I posted as its not obvious what it does , nor is it as flexible as your code , eg it can only ever do one thing.
its just that I have ended up using it , or similar , for exactly the kind of situation that ACJ had which seems to crop up a lot in file or csv-type-DB-fields work.
if though that makes me a wuss ... well then wheres that tutu ? :D
Celtboy 12-20-2003, 07:55 AM true. Just put the code in a function, and it's doing its single purpose in life, just like any good function will.
To be honest, I'm a tad amazed that my code worked at all ;) lol. Writing code quickly can sometimes produce dangerous results ;)
I should have DEFINITELY mentioned to try that on a test file, or on a copy of the original first. heehee. Hindsight is what you see when you bend over, er, 20/20...yeh....
Celtboy 12-20-2003, 07:56 AM ps. I think jkd has the tutu ;)
pps. I've gotta do this...at least once....
AUSSIE AUSSIE AUSSIE......
ACJavascript 12-20-2003, 04:00 PM AUSSIE lol
I've got a couple friends down there. LONG LIVE KOALA BEARS lol!
Anyways
Thanks again fire,
and celt boy your code was awesome it did its job, if would just put the values back I would of used it.:thumbsup:
|
|