PDA

View Full Version : Replace certain phrase throughout DB??


007
02-11-2003, 09:17 AM
Is it possible to replace a :smile: phrase throughout a DB with : ) (without the space obviously)????? I need to know because I imported posts from another (non VB) message board and all the emoticon "calls" are different than what I would like them to be. Is there any way I can replace all these in like 20,000 posts lol???

Also, this was a post only import, so all the usernames come up as userid=0. Are these names actually saved to any place that I could possibly individually add userid's to them?

I'm guessing the answer is no for both of these, but maybe somebody else has done this before? If anyone can offer any suffestions I'd appreciate it. THANKS! :classic:

Xenon
02-11-2003, 10:51 AM
first: replace hack was coded by the sisko :) (search for it :))

second: well, you can write a small script, which get's all usernames out of the posts and creates a user entry in the database, this ist possible :)

007
02-11-2003, 11:08 AM
THANKS! I didn't think either of these were possible. As least the first one was. :) That was the easiest hack I have installed to date lol. :) Thanks for pointing that out for me.

Xenon
02-11-2003, 11:20 AM
:)
you're welcome :)

the second:
create a file called createusers.php
<?php
require('global.php');
$usernames=$DB_site->query("SELECT DISTINCT username FROM post WHERE userid=0");
while ($username=$DB_site->fetch_array($usernames)) {
//does user exist?
if(!$userid=$DB_site->query_first("SELECT userid WHERE username='".addslashes($username)."'")) {
$DB_site->query("INSERT INTO user (userid,username,password,joindate) VALUES (NULL,'".addslashes($username)."',MD5('".addslashes($username)."'),".time().")");
$userid=$DB_site->insert_id();
$DB_site->query("INSERT INTO userfield (userid) VALUES ($userid)");

}$DB_site->query("UPDATE post SET userid=$userid[userid] WHERE userid=0 AND username=".addslashes($username));

}?>

copy this file into your forum dir and run it, it should create the users :)

007
02-11-2003, 11:27 AM
oohh.. !! thought you said it wasn't possible :) cool. looks scary, *backs up db first* ;) i trust you man, but just in case. i'll let you know how it goes :)

007
02-11-2003, 11:34 AM
Database error in vBulletin 2.2.9:

Invalid SQL: SELECT userid WHERE username='Array'
mysql error: You have an error in your SQL syntax near 'WHERE username='Array'' at line 1

mysql error number: 1064

hmmm, don't mean to bug you but what does this mean?? thanks again. :) seems like nothing bad happened but it wouldn't let me run that file I just made...

Xenon
02-11-2003, 12:14 PM
yeah, sorry, my fault :)

use this:
<?php
require('global.php');
$usernames=$DB_site->query("SELECT DISTINCT username FROM post WHERE userid=0");
while ($username=$DB_site->fetch_array($usernames)) {
//does user exist?
if(!$userid=$DB_site->query_first("SELECT userid FROM user WHERE username='".addslashes($username[username])."'")) {
$DB_site->query("INSERT INTO user (userid,username,password,joindate) VALUES (NULL,'".addslashes($username[username])."',MD5('".addslashes($username[username])."'),".time().")");
$userid=$DB_site->insert_id();
$DB_site->query("INSERT INTO userfield (userid) VALUES ($userid)");
$userid['userid']=$userid;
}$DB_site->query("UPDATE post SET userid=$userid[userid] WHERE userid=0 AND username=".addslashes($username[username]));

}?>

007
02-11-2003, 12:46 PM
Database error in vBulletin 2.2.9:

Invalid SQL: SELECT userid WHERE username='Dark Master'
mysql error: You have an error in your SQL syntax near 'WHERE username='Dark Master'' at line 1

mysql error number: 1064

any ideas? if this is going to be too much trouble please let me know. :) i'll understand.

Xenon
02-11-2003, 01:07 PM
lol, silly me, have forgotten from which table it should take the userid ^^

i've updated my post above :)

007
02-11-2003, 07:44 PM
Database error in vBulletin 2.2.9:

Invalid SQL: UPDATE post SET userid= WHERE userid=0 AND username=Dark Master
mysql error: You have an error in your SQL syntax near 'WHERE userid=0 AND username=Dark Master' at line 1

mysql error number: 1064

:) wahoo! lol hmmm, this looks sort of like the last one I got. any ideas?? thanks.

007
02-11-2003, 07:48 PM
k just ran it again (thinking it would work somehow) and it did sort of... but it did this:

Database error in vBulletin 2.2.9:

Invalid SQL: UPDATE post SET userid=5 WHERE userid=0 AND username=Dark Master
mysql error: You have an error in your SQL syntax near 'Master' at line 1

mysql error number: 1064

how do I delete user Id's? that last one seemed to make a user ID 5 which I don't want unless it is an actual user lol. any help? I don't want to just delete the user, but also the id, if that's possible.

Xenon
02-11-2003, 07:50 PM
hmm, shouldn't happen normally, but try this code instead..

<?php
require('global.php');
$usernames=$DB_site->query("SELECT DISTINCT username FROM post WHERE userid=0");
while ($username=$DB_site->fetch_array($usernames)) {
//does user exist?
$user=$DB_site->query_first("SELECT userid FROM user WHERE username='".addslashes($username[username])."'");
if(intval($user[userid])==0) {
$DB_site->query("INSERT INTO user (userid,username,password,joindate) VALUES (NULL,'".addslashes($username[username])."',MD5('".addslashes($username[username])."'),".time().")");
$userid=$DB_site->insert_id();
$DB_site->query("INSERT INTO userfield (userid) VALUES ($userid)");
$DB_site->query("UPDATE post SET userid=".intval($userid)." WHERE userid=0 AND username='".addslashes($username[username])."'");

} else {
$DB_site->query("UPDATE post SET userid=".intval($user[userid])." WHERE userid=0 AND username='".addslashes($username[username])."'");
}

}?>

Xenon
02-11-2003, 07:54 PM
sorry, typos ^^

use the updated version now :)

007
02-11-2003, 07:54 PM
did you see my second reply? (i edited it right after posting so check if that one applies too) thanks for all this help xenon. :)

Xenon
02-11-2003, 07:59 PM
the user would work perfectly, no need to delete him :)

007
02-11-2003, 08:03 PM
well the only thing is when clicking to go to the profile it still goes to this:

.../forums/member.php?action=getinfo&userid=0

so no profile and it also doesn't make the "post started a link." should it? if not then I guess this does work fine. :) just in case though, if I deleted the user then what querie would I run to update the user Id's and only have the original 4? so the next person who registeres would be 5, and so on? thanks.

Xenon
02-11-2003, 08:06 PM
when you delete the last user, the autoincrement would go back normally, so the next would be 5 again...

also if not, it's really not needed to have defragmented userid's ;)

007
02-11-2003, 08:15 PM
hmmmm, now it's gone haywire on me:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@"domain.com" and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

it was worth a try. thanks. it did work for that one user but then it didn't update the user information on old posts, like when I click the profile it still went to userid=0. i really don't think that this is possible :-/ lol. maybe it's just me and me lack of "knowing what I'm doing" but I guess the old users can just reregister lol. 3 mods already have (one under the same name as their old one) and when I open it to public, I can just leave a note in the registration pages about it. i don't wanna keep you here lol. thanks anyway. the search and replace hack you told me about was awesome. thanks.

Xenon
02-11-2003, 08:19 PM
hmm, the script is working now...
something quite similar has been made here some time before...

just retry it if the error occurs again, you should perhaps ask the host...