tomek142 Posted October 3, 2010 Share Posted October 3, 2010 I had a quick PHP crash course for my Programming Language class and have received an assignment to do. The problem that I have is getting data from a database. I have done a little test to see if everything is ok and I have found a problem. In my database I have a single table (called Schema) and two columns, plaintext and cyphertext. Both columns are CHAR type so the plaintext columns has a single character and the cyphertext columns has the corresponding rotate-13 character of the plaintext column. So I have something like this: plaintext cyphertext T G a n When I do a select query I just wanted to select the 'T' and the 'G' and echo them on the screen. My input file only includes one 'T' and no 'a'. When I run my code I get three 'TG' and three 'an' echoed but was thinking I will get only one 'TG'. I'm sure there is something wrong with my database and not with the php code. <?php function connect() { $link = mysql_connect('127.0.0.1','root','root'); if(!$link){die('Could not connect: ' .mysql_error());} if(mysql_select_db('Schema') === false) {die('Cound not select database: ' .mysql_error());} return $link; } $input = file_get_contents($argv[2]); if($input === false) { echo "An error has occurred on file $argv[2]\n"; exit(); } $link = connect(); for($i = 0;$i < strlen($input);$i++) { $result = mysql_query("SELECT * from Cypher WHERE plaintext= '" .$input[$i]."';"); if(!$result){die('Invalid query: ' .mysql_error() ."\n");} if($row = mysql_fetch_object($result)) { echo $row->plaintext; echo $row->cyphertext; echo "\n"; } } mysql_close($link); ?> Input file: Tomek John Output TG TG an an TG an Link to comment https://forums.phpfreaks.com/topic/215076-noob-question/ Share on other sites More sharing options...
tomek142 Posted October 4, 2010 Author Share Posted October 4, 2010 I figured it out. The problem was case sensitive. A 't' and 'T' are the same in mysql but adding the BINARY operator made it work the way i wanted it. Link to comment https://forums.phpfreaks.com/topic/215076-noob-question/#findComment-1118722 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.