Jump to content


Photo

Odd behavior of MySQL functions


  • Please log in to reply
2 replies to this topic

#1 s0urce

s0urce
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 19 September 2003 - 08:10 AM

I have the following lines in my php code:

[php:1:46b06602e6]<?php
$Query1 = \"insert into table values (NULL, \'$user\', PASSWORD(\'$pass\'))\";
$Result1 = mysql_query($Query1, $DB);
$Query2 = \"select * from table where user=\'$user\' and pass=PASSWORD(\'$pass\')\";
$Result2 = mysql_query($Query2, $DB);
echo mysql_num_rows($Result2);
?>[/php:1:46b06602e6]

(column names are correct)
What is echoed is the number of rows returned. The number echoed is zero (0). How is that possible? Am I doing something wrong?
The same thing happens when I use an MD5 function. Also, I tried inserting new row with phpMyAdmin, and then reading it in php, but still it returned nothing. I also tried adding a new row in a console window, then reading it (with select) in a console window, and mysql returned an empty set.
However, when I try doing it without using mysql functions, then it works. For example, this works perfectly:

[php:1:46b06602e6]<?php
$Query1 = \"insert into table values (NULL, \'$user\', \'$pass\')\";
$Result1 = mysql_query($Query1, $DB);
$Query2 = \"select * from table where user=\'$user\' and pass=\'$pass\'\";
$Result2 = mysql_query($Query2, $DB);
echo mysql_num_rows($Result2);
?>[/php:1:46b06602e6]

What\'s wrong with the functions?

S0urce
s0urce

#2 pauper_i

pauper_i
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts
  • LocationPhoenix, AZ, USA

Posted 21 September 2003 - 03:36 AM

Not too sure on this one but ...
What is the field size defined for the password in the database?

I ask because there was a change in the password hash function in MySQL 4.1 - previous to this version, the hash function produced a 16 byte hash - after 4.1 it produces a 41 byte hash so if the table was created in the older version, its possible that the field isn\'t big enough.

By not using the hash function, the password is probably small enough to fit into the field.

Failing that, try a \'die\' clause to the insert statement to print out any error messages.

Hope that helps!

D
Genius is one percent inspiration, and ninety-nine percent perspiration. [br]Thomas Alva Edison

#3 s0urce

s0urce
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 21 September 2003 - 08:32 AM

uhh... :oops:

Loks like the field was too small. I made it bigger and it now works.

Thanks,
S0urce
s0urce




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users