cc:'d to poster

From: "Chris MacKenzie" <[EMAIL PROTECTED]>
> > Either one of the unknown queries in edit_exam_question.inc
> > is truncating the data or the url parameter is truncated, or
> > dbconn.inc is the culprit.
>

> I've attached the two missing files, so this should help to diagnose
> what I've stuffed up.
>

O.K.

Now we know what is likely going on.

In  dbconn.inc we have ...
$conn1=mssql_pconnect($dbservername,$dbusername,$dbpassword);
//  pconnect is not doing what you think it might be
// a persistent connection reuses open libnks and any
// mssql_close() calls are ignored ... it is *persistent*
// not even script end will close the bugger
// suggest change to normal mssql_connect()
// especially because pconnect reuses open links - it will not
// create a new handle, thus making your multiple use of result
// below a bit of a problem
// N.B. -  mssql_connect() called with identical arguments
// will not open a new connection - consequences below

if(!$conn1) {
 print "Cannot Connect to SQL Server. Please contact your system
administrator.";
 exit;
}
$result=mssql_select_db($dbname,$conn1);
// first use of $result - pconnect will always use this handle

if(!$result) {
 print "Cannot Select SQL Database.<BR>";
 mssql_close($conn1);
 exit;
}

In edit_exam_question.inc we have ...

include('dbconn.inc');
$sql="SELECT * FROM tbl_exam_questions WHERE question_id=$question_id;";
$sql1="select * from tbl_exam_answers WHERE question_id=$question_id order
by id;";
// why separate this data?
// wouldn't a single query be faster and perhaps pre-collate the data you
// need in a faster and cleaner fashion?
// from other code it seems you need a single row returned structured
something
// like [exam_question]:[answer_1]:[answer_2]: ... [correct_answer], or
// whatever corresponds to your table data defintion schema
// if everything is a simple as it seems then a straightforward left join
// is proably your ticket home

$result=mssql_query($sql,$conn1);
// second use of $result
// there may not necessarily be a problem here but it costs nothing
// to use $result_sql1 or some such

if(!$result) {
// things might clear up a bit if this $result is differntiated from other
$results
 print "No Records Found.<BR><BR>";
 mssql_close($conn1);
// with msssql_pconnect() this line is irrelevant
 exit;
}

$result1=mssql_query($sql1,$conn1);
if(!$result) {
//////// RED FLAG /////////
// ! $result != $result1
// why $result1 when next step is an if on $result ?
// this is where clearly delineated $result vars will help
// if you had $result_sql1 it might have been easier to
// write if(!$result_sql1) instead of msiwriting as above

 print "No Records Found.<BR><BR>";
 mssql_close($conn1);
// again irrelevant with mssql_pconnect()
// a single mssql_close() at end of script is suffcient
// for each connection
// collecting them together at the end is a nice way
// of making sure the barn door is closed after you've
// let out some of the herd, although end-of-script
// will close non-persistent connections
 exit;
}

# Can't seem to find a good way to copy the returned array
# so I'll use a kludge and just re-submit the query.
# There must be a better way, but I'm pressed for time :-(
// see above about left join in a single query
// write a better single query and clear up the result vars
// include everything you need in one query
// faster and makes subsequent code simpler

$result2=mssql_query($sql1,$conn1);
if(!$result) {
//////// RED FLAG #2 //////
// rinse lather repeat
 print "No Records Found.<BR><BR>";
 mssql_close($conn1);
// irrelevant, but if you were using mssql_connect() instead of
mssql_pconnect
// you might not be wanting every query reopening conn1 to the db
// withiout explicti connection call queries try to open a connection
// on their own - why not just open one connection for one query
// and close it at the end?
 exit;
}


$numrows = mssql_num_rows($result);
$numrows1 = mssql_num_rows($result1);
# $numrows2 = mssql_num_rows($result2);

//[snip]

$row = mssql_fetch_array($result);
// there are some things that might be said about query result sets being
// retained in memory, but I don't think there's any need to go there
// try changing to mssql_connect()
// write a single left join query,
// clean up the ambiguities in re handle vars
// use a single mssql_close() at end of script


Not sure what else I can offer at this point.
Hope some of this helps you move on your way.

Pan



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to