Bizzet
-
Posts
2 -
Joined
-
Last visited
Posts posted by Bizzet
-
-
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 enterwww.mywebsite.com/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.=======================================================================
<?php try { $username = '******'; $password = '******'; $conn = new PDO('mysql:host=******;dbname=**********', $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch(PDOException $e) { echo 'ERROR: ' . $e->getMessage(); } $stmt = $pdo->prepare('SELECT COUNT(*) FROM wordlist WHERE words LIKE :aword'); $stmt->execute(array('aword' => "%{$_GET['word']}%")); return ($stmt->fetchColumn() != 0); ?>
What did I do wrong? I get this errorFatal error: Call to a member function prepare() on a non-object in ***** on line 11I barley know PHP....
Check if column within MySQL database contains a string.
in PHP Coding Help
Posted · Edited by Bizzet
Sorry for the obvious mistake...
How exactly would I make it echo true or false if the database contains the string though?