Forum Moderators: coopster

Message Too Old, No Replies

Checking database connectivity

         

theriddla1019

10:21 pm on Jan 14, 2004 (gmt 0)

10+ Year Member



After tons of testing and testing and testing i am positive my sql script is right and the value its testing is being populated. But i still get no value's returned from the database. I put error trapping on the query $Result = mysql_query($Query, $Link) or die(mysql_error()); which it passes with no problem...but still no data being retrieved. Is there anyway to test the connection to the database from within the script to make sure its opening it properly? Being new to this stuff is rather frustrating :P
Here is my connection to the db which i use in other forms and it works fine and i use actually a very similar sql string in another page and it works fine...

<?

$key = $HTTP_GET_VARS['key'];

require("POC_connect.php");
$Link = mysql_pconnect($Host, $User, $Password);
if (! $Link)
die("Couldn't connect to MYSQL");
mysql_select_db($DBName, $Link);

$Query = "SELECT * FROM poc WHERE POCID = " . $key;
$Result = mysql_query($Query, $Link) or die(mysql_error());
while($Row = mysql_fetch_assoc($Result));
$ProviderID = $Row['ProviderID'];
$MR = $Row['MR'];
$UPIN = $Row['UPIN'];

$Query2 = "SELECT * FROM patientdata WHERE MR = '" . $MR . "'";
$Result2 = mysql_query($Query2, $Link) or die(mysql_error());
while($Row2 = mysql_fetch_assoc($Result2));
$Last = $Row2['Last'];
$First = $Row2['First'];
$MI = $Row2['MI'];
$HCNum = $Row2['HCNum'];
$SOC = $Row2['SOC'];
?>

wruk999

10:40 pm on Jan 14, 2004 (gmt 0)

10+ Year Member



Hi.

Are you not receiving any error messages? Just not data returned.

Could it be in this line, that it is not actually passing the value $key to the sql statement.

$Query = "SELECT * FROM poc WHERE POCID = " . $key;

I think that it might be closing after POCID = "

Try, somewhere, echo'ing the value of $Query to your page, and see if your sql statement is as it should be, ie: including the $key value.

Let us know,
wruk999

coopster

1:27 am on Jan 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Your problems may be starting with your (lack of)
while
loop. I notice you are using while [php.net], but you aren't actually looping. If you only intend to receive one row back, don't use
while
, otherwise, finish processing your loop...

You currently have...


while($Row = mysql_fetch_assoc($Result));

...when you should have

$Row = mysql_fetch_assoc($Result);

sage

2:47 am on Jan 15, 2004 (gmt 0)

10+ Year Member



I would try inserting some debugging code into your software. I often do this when debugging my software in a complex environment especially where network connections are involved. I typically print to my screen values of key variables and data structures. I also use phrases allowing me to know if I made it through a particular piece of logic -- especially where I have used conditional statements that might require this type of analysis.

Another useful debugging tool is the network sniffer. This tool is not for the faint hearted. It requires extensive network protocol knowledge as well as some skill in the operation of the software or device depending on what you choose or have access to. Data General's sniffer (a dedicated device -- hardware and software, tcpdump or Ethereal (both software programs running on Unix or Windows) are examples of this type of tool.

By trapping whole packets you may be able to see what is being transmitted. Beware what is not decoded as a particular protocol, or ascii is often decoded as Hex. I have included this information in case you are familar with network protocol detail and have done some sniffing. If you are not and would like to know, it is a LAN manager tool often used in network trouble shooting.

theriddla1019

3:20 pm on Jan 15, 2004 (gmt 0)

10+ Year Member



I actually inserted the while when i found a website that showed how to debug, first few runs it ran into an error Query does not contain data. then i found the ' i was missing and fixed it then it ran through with no problems...i looked at Coopsters post and realized before it was getting an error so it was dying at the $Result stage of the problem. Then when there was no errors it was continuing past that problem and for some reason unknown to me i put in that while loop cause i thought it had something to do with the error trapping. *Bonk*
Anyways thanks once again for setting me straight...i think im starting to get the hang of this.
Riddla