[thelist] merging a dictionary to sql table

Matt Warden mwarden at gmail.com
Wed Nov 16 01:10:36 CST 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alex Beston wrote:
> hi List
> 
> im trying to merge one dictionary with another already in a couple of 
> columns of a dictionary table. heres my code. its not really working - 
> no words get inputted to the dictionary
> 
> any ideas appreciated
> 
> Alex
> 
> <?
> $time_start = microtime(true);
> include("database/connect-dictionary.php");
> $handle = fopen("ENGLDICT.TXT", "r");
> $counter=0;
> if ($handle) {
>     while (!feof($handle)) {
>         $buffer = trim(fgets($handle, 4096));
>         $query_string = "SELECT word FROM word_list WHERE word = 
> '$buffer'"; 
>          
>         $result = mysql_query ($query_string);// or die("not working1"); 
>          
>         if(!$result){  // this might be a bad way to do it
>             $query = "INSERT into word_list(word) VALUES ('$buffer')";
>             mysql_query($query);

I suspect your $query here isn't what you think it is. Have you output
its value?

Also, you should do:

mysql_query($foo) or die(mysql_error());

while you're debugging. If tyou don't want these messages when you're done:

define(TEST_MODE, true);
...
mysql_query($foo) or (TEST_MODE and die(mysql_error()));

When you're done debugging, set TEST_MODE to false.

(Obviously you could also wrap this in a debug function.)

- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDettrrI3LObhzHRMRAuYuAJ0ZTeacm9F8pFXZ6F29V4pX6+0H9ACffKlr
xmOGbX9tBdwR1zQS0fz4GkE=
=ev9z
-----END PGP SIGNATURE-----



More information about the thelist mailing list