PDA

View Full Version : Ending Server Processes and Sorting PHPMyAdmin view.



andy
04-04-2004, 04:17 PM
1- I notice I have PHPMyAdmin processes that are in the state of "sleep" after I query my database. They usually vanish after 5-10 minutes. I'm new to PHP. I'm pretty sure I need to do a...
mysql_free_result($Recordset1); (this was a database query)
for every database lookup I do, but do I also need to do a ...
mysql_free_result($variable1); (this was a variable)
for every variable I set in the PHP session?

2- In PHPMyAdmin's main view (clicking on the magnifing glass over the little piece of paper) which does a browse of my database table records it sorts the results in an order I'd like to change. I have one autoincrement primary key, and I would like the view to always sort by that key. How can I do this?

Thanks again for the help.

wildjokerdesign
04-04-2004, 04:29 PM
I don't think you need to do it when on the variables that you set just on the queries that you do of the database. Or at least that is how I see it if I am understanding your question. Hopefully someone well correct me if I am wrong.

Not sure on the sorting for phpMyAdmin. I'll go take a look and see if I can come up with an answer for that one.

FZ
04-04-2004, 04:50 PM
1. I'm not sure what you mean by processes here? How are you checking? Also, I would not worry too much about this. I'm sure the WestHost servers are more than capable of handling a few extra processes, and like you say they go away after a few minutes anyway. I would just recommend you code your own PHP with the mysql_free_result "in mind", and not worry about doing it for PHPmyAdmin - it'll get really tedious!


2. If you are using the version of PHPMyAdmin that is available via your Site Manager, it is really out of date - I installed the latest version and it has column sorting (I just checked to make sure). You can get the latest version from: http://www.phpmyadmin.net (I recommend the latest stable version). It is really easy to install, but SSH would be involved (i.e. you need to install it via an SSH session). It's literally just unzipping into a directory, setting one or two config variables and that's it!

wildjokerdesign
04-04-2004, 06:34 PM
On your number 2 question. If you do not want to install the latest version that FZ mentioned you should be able to acomplish what you want by going to the table in mind and then click on Operations. On the resulting page you should find an "Alter table order by". I think that is what you want. The only thing I am not sure of is if it holds for your next session in PhpMyAdmin.

I figured that one out after going through all the steps to activate the added features for phpMyAdmin. That went pretty smooth but not really sure if they would help with this. In fact not to sure how to use them now that I have them. :) It does add a bookmark feature for queries that could come in handy. Activates the relation and pdf options also and something called Data Dictionary. Could be this is all extras not really needed but gives me something new to learn.

Fayez, Does the new version have these features set up by default? Or do you still have to go through the steps of setting up the database and tables for them?

FZ
04-04-2004, 06:58 PM
Shawn, as far as sorting columns is concerned, this is done by clicking the column heading, so that is "enabled by default". "Operations" is still available, and it provides what you spoke of in your post, though I could not find "data dictionary", "pdf", etc. but I am sure they just moved that to some other section.

andy
04-04-2004, 09:57 PM
FZ,
I'm checking the processes through PHPmyAdmin and choosing the "(Databases)..." link in the upper left hand corner. From That screen it has "Show Processes" in the main screen. I'm not that concerned with them, but I'm thinking that I might as well close any database link's if I can. I'm new to PHP and didn't know if in my PHP script I need to close these connection, or if it's normal for them to remain open. Example...
I look at the "Show Processes" as stated above...
The only process is my current one which shows a process in the SQL Query field of "SHOW PROCESSLIST" because I'm current viewing the DB...
I then place an order to my DB via the web through a PHP page and when I view the process page again I'll see a process with a status of "Sleep" with no SQL Query info.
After a while it will disappear. Should I be killing this process through PHP at the end of the PHP script? And what causes a connection to remain open? Hope that made sence!

Also my version of PHPMyAdmin does have column sorting, but I'm just tired of having to click on the top of that column to sort it. Wondering if I can set a default?

WildJoker,
I did try the "alter table order" function and it did not save the setting?

Thanks guys!!!

wildjokerdesign
04-05-2004, 07:48 AM
Andy do you close the connection to the database at the end of your script?

I was looking at the phpBB script to check and see what it was doing at the end and it looks like it is checking to make sure that results have been freed and then closes the database. It calls this function at the end.


function sql_close()
{
if($this->db_connect_id)
{
if($this->query_result)
{
@mysql_free_result($this->query_result);
}
$result = @mysql_close($this->db_connect_id);
return $result;
}
else
{
return false;
}
}

UPDATE:
I could be wrong on this one. The "book" says that there is not the need to close the connection that php auotomatically closes it before the end of the script. That being said every example of a script that I use to connect to a database some how closes the connection at the end of the script. To make things a bit clearer below is a simplified version of opening the connection and then closeing it.


$connection_id = mysql_connect('localhost', 'username', 'password');

mysql_close($connection_id);