PHP-DB - Check if column within MySQL database contains a string.
Discuss Check if column within MySQL database contains a string. in the PHP Development forum on Dev Shed. Check if column within MySQL database contains a string. PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 4
Time spent in forums: 20 m 33 sec
Reputation Power: 0
PHP-DB - Check if column within MySQL database contains a string.
Bizzet, on 20 Mar 2013 - 09:08, said:
Okay, so basically what I want to is create an API using PHP which will allow my program to check if a column within a table contains a certain string.
For example,
Say I enter
/api.php?word="ANY WORD"
The script would echo true or false if the database contained that word or not.
I am using a MySQL database and I have no idea how to go about this.
$stmt = $conn->prepare('SELECT COUNT(*) FROM wordlist WHERE words LIKE :aword');
$stmt->execute(array('aword' => "%{$_GET['word']}%"));
return ($stmt->fetchColumn() != 0);
?>
How exactly would I make it echo true or false if the database contains the string though?
Please try to post code, its hard for me to translate text to PHP...
Posts: 1,867
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 33 m 7 sec
Reputation Power: 813
Quote:
Originally Posted by Bizzet
Bizzet, on 20 Mar 2013 - 09:08, said:
When you copy and paste, at least remove the leftovers from the last forum and make sure to include all content. Where's the PDO exception from the other forums? Did you want us to guess?
Since there's obviously something wrong with your PDO object, that's what you need to fix first.
The code you gave us can't be the exact code -- or you're getting the error in some other file. So what is your actual code?
C'mon, if you want us to help you, at least don't throw obstacles in our way.
Posts: 4
Time spent in forums: 20 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by Jacques1
When you C&P, at least remove the leftovers from the last forum and make sure to include all content. Where's the PDO exception from the other forums? Did you want us to guess?
Since there's obviously something wrong with your PDO object, that's what you need to fix first.
The code you gave us can't be the exact code -- or you're getting the error in some other file. So what is your actual code?
C'mon, if you want us to help you, at least don't throw obstacles in our way.
I am not getting any errors when running that code. I don't know what you mean the "PDO exception from other forums".
I do not know what is wrong with my code and I do not know what else information you want. If you need more, please be more specific.