A handy note .. if you are only accessing one database host (and mostly that will be the case) , you dont even need to pass all the database connections around , once php has made a MySQL connection , it will reuse that connection wherever it can , unless you close it its always available...

there are many good reasons for not having ANY sql calls within the classes themselves and abstracting the database work elsewhere , but thats another story.

SDP2006

01-02-2004, 03:21 PM

Thanks, my script works now.

SDP2006

01-02-2004, 03:27 PM

One more question. How do I change my MySQL Query to where it adds to the current total in the field. Like if there were 2 warning points and you wanted to add 2 more that would give a total of 4. How might I do that?

Fuction warnUser() is okay, but I don't believe function printPts is. My errors are
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\server\htdocs\warn.php on line 27

Notice: Use of undefined constant user - assumed 'user' in c:\server\htdocs\warn.php on line 28

Notice: Use of undefined constant wpts - assumed 'wpts' in c:\server\htdocs\warn.php on line 29

?>
My problem now is in function printPts all that is printed is 'has warning points!' I dunno why. All help is welcome....

-Thanks

raf

01-03-2004, 02:02 AM

Firepages :
A handy note .. if you are only accessing one database host (and mostly that will be the case) , you dont even need to pass all the database connections around , once php has made a MySQL connection , it will reuse that connection wherever it can , unless you close it its always available...

I think that if you use mysql_connect(), that the connection is then automatically closed when the script is processed.

You need to use mysql_pconnect() if you want persistent connections and optimize your serverperformance with connectionpooling.

Note : using persistent connections will result in always having a number of 'sleeping connection' and requires more RAM.

SDP2006 : you should be extremely carefull when you use variables to store your accountdetails in like
<?php
$host = "localhost";
$dbase = "testing";
$user = "root";
$pass = "rootpass";
?>
Always set these variables explicitely to '' as soon as you no longer need them or unset() then !!

SDP2006

01-03-2004, 02:56 AM

Okay, so I changed it to mysq_pconnect() and I'm still having the problem above ^.

Thanks for all the help. Is is greatly appreciated.

mordred

01-03-2004, 03:16 AM

Have you made sure the SQL query works as expected? Try these steps:

1.) add "if (!$result) print mysql_error();" to see any potential MySQL error messages.
2.) print out the SQL query used
3.) run the query (as it was printed out!) in phpMyAdmin and check that it returns the expected result sets.

firepages

01-03-2004, 04:04 AM

Originally posted by raf
I think that if you use mysql_connect(), that the connection is then automatically closed when the script is processed.

yes , so in the scope of a script (eg page) unless you explicity close and reopen your connections the connection is not 'lost' until the script finishes.

eg one connection in 'config.inc' is valid thoughout the lifetime of the script that called it.

when you use mysql_pconnect the connection stays (or attempts to) stay in memory across requests hence the overhead an dis mostly best avoided unless you have a `difficult` connection or say a seperate data-tier.

SDP2006

01-03-2004, 02:37 PM

Originally posted by mordred
Have you made sure the SQL query works as expected? Try these steps:

1.) add "if (!$result) print mysql_error();" to see any potential MySQL error messages.
2.) print out the SQL query used
3.) run the query (as it was printed out!) in phpMyAdmin and check that it returns the expected result sets. Yes, I ran the code in PHPMyAdmin and it returned results as I expected.

I found the problem, it was my query. Not the query, but the WHERE user='{this->user}'. I had a user that didn't exist in the $user in the function.