search for a word in the database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

search for a word in the database

Post by PHPForever »

I think this is more of a sql question than a php one but since my application is in php, I just thought I'd ask it here.

I'm trying to find occurences of a string in my database. Is there a way to do that ?
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: search for a word in the database

Post by yacahuma »

select * from mytable where mycolumn like '%partofthestring%'
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: search for a word in the database

Post by pickle »

Moving to Databases. The programming language is irrelevant when you're doing SQL queries.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Attero
Forum Newbie
Posts: 18
Joined: Thu Jan 29, 2009 9:35 am
Location: Farnborough, UK

Re: search for a word in the database

Post by Attero »

You should have a look at using the SQL function, LIKE.
You would find it a lot easier to use MATCH() AGAINST() in fulltext searches.

Look up MATCH() AGAINST() for MySQL in google.
You will need to make sure you know how to make fulltext catalogs in MySQL.

It's as easy as going:

Code: Select all

 
SELECT * FROM TABLE
WHERE MATCH(field1, field2, field3) AGAINST('search goes here')
 
PHPForever
Forum Newbie
Posts: 14
Joined: Sun Aug 31, 2008 11:31 am

Re: search for a word in the database

Post by PHPForever »

I was looking to search the database and not the table. Thanks though.

I found that phpMyAdmin has an UI interface which lets you to view the databases and also allows you to search for a string in the entire database.
Post Reply