MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 24th, 2004, 05:25 PM
cdvrooman cdvrooman is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 cdvrooman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
False mysql query results

I've run into a problem that is quite frankly baffling the heck out of me.

I'm using PHP 4.3.4 / MySQL 4.0.14 / Redhat 8.3 and PHP 4.3.4 / MySQL 4.0.16 / Redhat 8.3.

I have a database where I am performing some cleanup and I do the following:
1. Get and make a list of the current subjects a student is enrolled in.
2. Delete that list of subjects so the student isn't enrolled in anything at all.
3. Loop through the list of classes from #1, and...
a. Get the appropriate class the student *should* be enrolled in (based on his location and career)
b. Insert that information.
c. Check to make sure that information was inserted, and if it wasn't, then repeat the Insert.
d. If the information was inserted in 3.b. or the second attempt in 3.c, then insert in another table information associated with a related enrollment in a forum.
e. Perform similar checks as in 3.a. - 3.c. above.
f. Get the next class and repeat 3.a. - 3.e.

The mysql_query is handled by the following function:

function qAlumnos2($q, &$numRows, &$affRows) {
global $link2, $debug;

$numRows = $affRows = -1;
$r = mysql_query($q, $link2);
$which = strtoupper(substr($q, 0, 6));
if ($which == "INSERT" || $which == "UPDATE" || $which == "DELETE")
$affRows = @mysql_affected_rows($link2);
else
$numRows = @mysql_num_rows($r);
if ($debug) echo "qAlumnos2 AFFECTED_ROWS: $affRows, numRows: $numRows, q: $q<hr>\n";
return $r;
}

Here's the problem:
Half the time, the results I am getting from the affected_rows and num_rows are false
.
For example:
The first pass of inserting a student and his info:

qAlumnos2 AFFECTED_ROWS: 1, numRows: -1, q: INSERT INTO alumnos.inscripcion_net (alcodigo, macodigo, mmcodigo, infecha, ininscripto) VALUES (8860, 10, 1, '2004-03-24 18:22:30', '1')

Notice that "AFFECTED_ROWS" is returning a 1. That's a lie, nothing was inserted.

Now (since I don't trust my insertion) I check to see if the info was actually inserted:

qAlumnos2 AFFECTED_ROWS: -1, numRows: 1, q: SELECT macodigo FROM alumnos.inscripcion_net WHERE alcodigo = 8860 AND macodigo = 10

Notice that "numRows" is returning a 1. That's a lie too, nothing actually was Inserted after all.

The "qAlumnos2" function must be screwing things up you must be thinking... but it actually does what it should half the time (so it does work), and I'm using it elsewhere without problems. For example, when I delete the student's existing classes 1 by 1 (not efficient, but I'm performing other deletions related to each class).

So... I tried:

1. Establishing a separate $link variable when I connect to the database. It did not make a difference.
2. Eliminating the "qAlumnos2" function and using $r = mysql_query("SQL QUERY HERE...", $link2);
along with mysql_num_rows($r) and mysql_affected_rows($link2)
and I still had the same problems.

So, I'm basically lost at this point.

If anybody has suggestions, please toss them my way. I've got 10,000+ students I need to process ASAP, but if I process them now, basically all of them will be missing at least 1 or more classes.-

Thanks in advance,

Christopher D. Vrooman

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > False mysql query results


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway