Jump to content

Changing links

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Okay.. I have pretty bad problem..

I have to change over 150 links in database.. from http://localhost/wordpress
to my site's url.. Does anyone know how I can do it with PHP because I really don't wanna do it manually..
And thinking is so hard for me atm.. :D that's why I ask from you :D

#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
You don't need to use PHP, you can just use SQL. MySQL :: MySQL 5.0 Reference Manual :: 11.4 String Functions

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
So.. I do like this:

[highlight="sql"]
REPLACE ("http://localhost/wordpress", "http://localhost/wordpress", "http://mysiteaddress")
[/highlight]

or something?

#4
Guest_Jaan_*

Guest_Jaan_*
  • Guests
hmm.. I tried this:

$query = mysql_query("SELECT REPLACE('http://localhost/wordpress', 'http://localhost/wordpress', 'http://mysite')");
if(!$query){
	die(mysql_error());
}

But it didn't work

and I tried this in phpMyAdmin:

[highlight="sql"]
SELECT REPLACE('http://localhost/wordpress', 'http://localhost/wordpress', 'http://mysite');
[/highlight]

And it didn't work hmm :/

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
UPDATE links set address=REPLACE(address, 'http://localhost/wordpress', 'http://mysite');

will update ALL entries in the table links within the column address having 'http://localhost/wordpress' replaced to 'http://mysite'

#6
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Awesome.. it works mate !
thank you very much ^^