[PHP-DB] Trying to reduce the number of queries
$ID = $row_state["ID"]; // Get a count of the number of applications in this company's mailbox that are associated // with this media location $state_count = db_select_val("select count(*) from application, mailbox where mailbox.app_ID= application.ID and application.media_ID = \"$ID\" and mailbox.company_ID =\"$company_ID\""); echo "$state - $city - $name - $state_count\n"; } } I would like to incorportate each of the queries that uses the count(*) function into the associated query outside the while() loop. Can this be done? I assume that the fewer times I need to query the database, the faster my script will run. Is this true as well? TIA, Ryan Marks -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Cronjob
Hello all, I have a cronjob that runs a PHP script against MySQL. The script takes 5 minutes to process 4000 records (approximately 12 records per second). Here are the top two entries from top: PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND 8671 mysql 25 0 20172 19M 2000 R97.8 3.9 2:02 0 mysqld 8670 appmgr15 0 2088 2088 1424 S 2.2 0.4 0:03 0 php Is there a way that I can slow down the script so mysqld does not bog the machine down. Here is a snippet of code. The function is called by the cronjob. function rank_mailbox_current($company_ID){ $query = "select app_ID from mailbox where company_ID = \"$company_ID\" and deleted_date = 0 order by mailbox.ID desc"; $result=query_database($query); while ($row = mysql_fetch_assoc($result)){ $app_ID = $row["app_ID"]; $rank_of_app=rank_app($app_ID,$company_ID); } } Server: P-IV 2.4GHz, 512 DDRAM, RedHat 9 PHP Version 4.3.1 MySQL 4.0.3 Thanks, Ryan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] No tuples available
I Googled for your warning message and found this: http://www.phpbuilder.com/mail/php-windows/2000111/0024.php -Original Message- From: Ryan Jameson (USA) [mailto:[EMAIL PROTECTED] Sent: Thursday, November 13, 2003 5:52 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] No tuples available Is there a way to tell PHP to not show just this warning? Maybe there should be another warning level just for this warning, call it "trivial and pointless". :-) Warning: odbc_fetch_row(): No tuples available at this result index in I don't even know what it means. I get it all the time when I'm checking if my query returned results. It's kinda silly. Everything works fine & I'd like to leave error_reporting full so SQL errors that report as warnings will be displayed. Thanks! <>< Ryan -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] store whois requests
This is some code I already use... you may wish to change the way you retrieve you whois data. Ryan Whois Hostname: $host"; //backwards tick marks will run this command on the server and echo's it out to the screen echo `whois $host`; echo ""; //get the timestamp and ip $timestamp = date("YmdHis"); $ip = getenv(REMOTE_ADDR); //create your query $query = "insert into whois_log (domain, timestamp, ip) values (\"$host\", \"$timestamp\", \"$ip\")"; //run the query against the database with your variables for $server, $username, and $password $db = mysql_connect($server,$username,$password); mysql_select_db("your_database",$db); if (!$result = @mysql_query($query,$db)){ $error = mysql_error(); print("Error Processing Query: $error$query"); } } ?> document.theform.host.focus() -Original Message- From: IS [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 16, 2003 4:27 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: [PHP-DB] store whois requests I want to store whois requests including the ip address and date/time stamp into a file or MySQL database (a database is what I prefer to use) for monitoring the PHP whois script. Anybody an idea of how I could do this? I'm a beginner in PHP so any help is welcome. --IS -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Need to Run a PHP script using CRON or ?
My bad... wget does require http or ftp protocol and a hostname that can be resolved by the server. -Original Message- From: CPT John W. Holmes [mailto:[EMAIL PROTECTED] Sent: Monday, September 15, 2003 3:47 PM To: Ryan Marks; [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP-DB] Need to Run a PHP script using CRON or ? From: "Ryan Marks" <[EMAIL PROTECTED]> > Not necessarily. You can wget /path/to/file.php or my personal preference > is not to use wget, but php directly > /path/to/php/executable /path/to/file.php Are you sure about that? I thought wget had to go through HTTP? This didn't work for me, am I doing it wrong? $ ls cpanel3-skelmailpublic_html tmp cpanelbranding public_ftp test.phpwww $ wget test.php --16:42:22-- http://test.php/ => `index.html' Resolving test.php... failed: No address associated with hostname. ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Need to Run a PHP script using CRON or ?
Not necessarily. You can wget /path/to/file.php or my personal preference is not to use wget, but php directly /path/to/php/executable /path/to/file.php Just a thought, Ryan -Original Message- From: Jonathan Villa [mailto:[EMAIL PROTECTED] Sent: Monday, September 15, 2003 3:28 PM To: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Need to Run a PHP script using CRON or ? Interesting... how does this fair concerning security? So I'll have to have this file located in my document root, is this a good thing? My current directory structure consists of several files located outside the doc root. I guess I could always include it onto a page On Mon, 2003-09-15 at 14:49, CPT John W. Holmes wrote: > From: "Jonathan Villa" <[EMAIL PROTECTED]> > > > > I have an application which creates temporary tables. My plan is to > > remove them after a 24 hour period and only those which are have a > > created time greater than 24 hours. That part I can do, my question is > > how will I be able to run this script which is a 2 part script. > > > > First thing I do is pull the names of the temporary tables which are > > going to be deleted from another table. From this result set, I need to > > DROP tables as well as remove the reference to them from the first > > table. > > > > I understand that I can run PHP from the command line but this would > > require PHP to installed as a CGI which I prefer not to do. > > > > I was hoping I that I could use CRON to run this script once a day... > > You can. Create a php script that does what you want. It should not create > any output, either log status/error messages or send an email. > > If you save it as cron.php, you can use a command such as the following in > your crontab: > > wget -q -O - www.domain.com/cron.php > /dev/null > > I'm assuming you know the specifics of cron or can google for it. :) > > ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] subtracting dates...
I found this code at Google's cached version of the manual for the date() function: http://216.239.37.104/search?q=cache:kq0aNfZeEp8J:www.php.net/date+diffe rence+two+date+site:www.php.net&hl=en&ie=UTF-8 This code only returned the number of hours, minutes, and seconds between the two points in time. Now it returns years and days as well as the left over time. The script also used the mod operator (%) to find the remaining days after determining the year and it would not calculate correctly. For example, if I compared yesterday, three years ago(08-01-00) and today (08-02-03) at noon for both days, I would get a difference of 3 years. No I am using while loops subtracting whole years to find the number of days that remain. The same is true for subtracting days, hours and minutes. CODE: 31536000){ $r -= 31536000; } $dd=floor($r / 86400); while ($r > 86400){ $r -= 86400; } $hh=floor($r/3600); if ($hh<=9) $hh="0".$hh; //adds a leading 0 if less than 10 while ($r > 3600){ $r -= 3600; } $mm=floor($r/60); if ($mm<=9) $mm="0".$mm; //adds a leading 0 if less than 10 while ($r > 60){ $r -= 60; } $ss=$r ; if ($ss<=9) $ss="0".$ss; //adds a leading 0 if less than 10 $retval="$yy year(s), $dd day(s) $hh:$mm:$ss"; return $retval; } ?> OUTPUT: 19 year(s), 229 day(s) 05:22:01 Hope this helps, Ryan Marks -Original Message- From: John Ryan [mailto:[EMAIL PROTECTED] Sent: Saturday, August 02, 2003 2:31 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP-DB] subtracting dates... Hi, In mySQL, I store dates as -MM-DD, a standard DATE type. It stores users date of births. I need to calculate in a PHP script, the users age from this DOB. I get a PHP date in the same format as the mySQL and subtract, which returns the year rounded off. ie, it doesnt matter if your birthdays in june of 1983 and the date is januray 2003, your age is still returned as 20, when it should be 19. Does anyone know how can i get the right age? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] inputting datetime to mssql
Henrik, It's possible that the database is interpreting your date as a couple of subtraction operations. I always use quotes or single ticks around my dates when refrencing them in SQL. Example: INSERT into some_table (date) values ("2003-07-25"); Give a sample of your code so that your problem can be narrowed down. Ryan -Original Message- From: Henrik Hornemann [mailto:[EMAIL PROTECTED] Sent: Friday, July 25, 2003 9:18 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] inputting datetime to mssql Hi, I had this problem that was driving me crazy. I was trying to input a datetime to a mssql table, formated the same way as I use in all my other tables i.e d-m-Y. But no matter which variations of the basic format I tried, it didn't understand the date correctly. In desperation I tried something stupid, inverting the format to Y-m-d, which actually worked. My question is, how can this be possible that datetime fields in two tables in the same datebase requires the input date to be formated in different ways?? And is there any way to fix the odd one out? Regards Henrik Hornemann -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Passing key field, id, from form to procedure
Douglas, The form that shows the editable fields has a hidden field named 'DID' having the value of $zid. In your updaterecord procedure, you will have to use the variable $_GET[DID] instead of $zid. You can of course just add one line of code: $zid = $_GET[DID]; to help you out. One other trick is to echo out your query before actually running it so that you don't update all of your records by mistake. Ryan Marks -Original Message- From: Hull, Douglas D [mailto:[EMAIL PROTECTED] Sent: Friday, July 18, 2003 10:40 AM To: Note To php mysql List (E-mail) Subject: [PHP-DB] Passing key field, id, from form to procedure I am just starting to learn php and mysql. I have a small php/html page and database. All it does when starting shows the name of each person with a delete and edit link beside each name. At the bottom of the list there is an "Add Record" button. If you select delete it takes out the name and reloads the page. If you select "Add Record" it brings up a form to add a new name etc. with an "Add It" button under the form in which after selecting INSERTs the new record and reloads the initial page. The add and delete parts work fine. The edit record is the problem. After selecting the edit beside the appropriate name a form is brought up showing the current information for that record with an "Update Record" button under the form. This works fine to here. But when I select the "Update Record button it will go into the "updaterecord" procedure of my php/html page but it has no id for it to apply the UPDATE to. So how can I have it pass the id to the "updaterecord" procedure so it will apply the UPDATE to the appropriate record? I tried two different ways of getting the id for updaterecord as you can see below. Following is my editrecord and updaterecord procedures: if (isset($_GET['editrecord'])) { //edit record $zid = $_GET['editrecord']; $sql = "SELECT * FROM persinfo WHERE DID = $zid"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $zid = $row["DID"]; $zfname = $row["DFirst"]; $zlname = $row["DLast"]; ?> First name: Last name: If you want all of the code let me know. I could send it to your personal email address. The whole thing is probably 130 lines of code. Thanks for any help, Doug Hull -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Print Query
You may be able to view this report in Excel and print it from there. If this is an option, do the following in Excel: 1. Data -> Import External Data -> New Web Query 2. Enter the URL for your report in the Address field and click Go. It is possible to start at one URL and browse to the report if you need to authenticate. 3. Toggle the yellow arrow boxes to green checkmarks if you want to include that in your spreadsheet. 4. Click Import. You will lose your formatting, but this is an option that doesn't require writing any code. Ryan -Original Message- From: Norma Ramirez - TECNOSOFT [mailto:[EMAIL PROTECTED] Sent: Friday, July 18, 2003 8:13 AM To: lista php Subject: [PHP-DB] Print Query I´have a complex report from mysql via php whits css, frames etc... Someone know a script to make a printable versión of this? Thank´s Norma Ramirez -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Looking for a php database browser..
Using phpMyAdmin, you can grant a user specific privileges to do just what you are asking about. If you only want the data changed, give them some or all of these: SELECT, INSERT, UPDATE, and DELETE. You can specify how much the user can see or change at the level of the database, table, or column. The ALTER privilege allows the user to change the structure of the table. Ryan -Original Message- From: Daniel Szasz [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 3:29 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Looking for a php database browser.. Hello I have to give the possibilitz to browse the tables from a database and update the data inside. Since there are a lot of tables I prefer to use a smart php table browser. The user is not allowed to update the structure only the data so I can't use the phpMyAdmin that is already installed on the server. Thanks a lot for help Daniel -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php