Jump to content


Photo

Write output of Database Query to file


  • Please log in to reply
3 replies to this topic

#1 Kronos9326

Kronos9326
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 06 April 2006 - 01:49 AM

<table width="100%" border="0" cellpadding="0" cellspacing="0" class="BodyText">
        <?php do { ?>
          <tr>
                <td class="SmallText"><font color="#999999">RELEASED:</font> <a href="<?php echo $row_new['homepage']; ?>"><?php echo $row_new['name']; ?></a></td>
          </tr>
          <?php } while ($row_new = mysql_fetch_assoc($new)); ?>
      </table>

I've got the above script/query (and several others like it) that I would like to run every 20 minutes and write the contents to a text file. I would then include that file in various parts of the website. I am doing this to reduce the 'strain' of our DB server, since we've already run into problems with us running out of available connections.

Our server is running PHP version 4.3.11.

Can anyone help me with a simple PHP script that would do what I'm looking for. From there I'd apply to to the other queries I have running.

Any help would be appreciated.

David.

#2 DrDre

DrDre
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 06 April 2006 - 02:15 AM

Read reply below... Theres some code in these forums added by phpfreaks which is blocking the code needed :x
[a href="http://forums.fanetworks.net" target="_blank"][/a]
» faNetworks Webmaster. [[a href="http://fanetworks.net" target="_blank"]fanetworks.net[/a]]
» faSoftware Developer [[a href="http://software.fanetworks.net" target="_blank"]software.fanetworks.net[/a]]
» faForums - php Resource + more [[a href="http://forums.fanetworks.net" target="_blank"]forums.fanetworks.net[/a]]
» Experienced php Coder - Ill help anyone I can if I have time ;)

#3 Kronos9326

Kronos9326
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 06 April 2006 - 02:20 AM

[!--quoteo(post=362112:date=Apr 5 2006, 10:15 PM:name=DrDre)--][div class=\'quotetop\']QUOTE(DrDre @ Apr 5 2006, 10:15 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
hmm? 403 Forbidden on post
[/quote]

I don't understand.. what's this got to do with my question?

David.

#4 DrDre

DrDre
  • Members
  • PipPipPip
  • Advanced Member
  • 35 posts

Posted 06 April 2006 - 02:33 AM

<?
//mysql stuff to get $new
ob_start();
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="BodyText">
        <?php do { ?>
          <tr>
                <td class="SmallText"><font color="#999999">RELEASED:</font> <a href="<?php echo $row_new['homepage']; ?>"><?php echo $row_new['name']; ?></a></td>
          </tr>
          <?php } while ($row_new = mysql_fetch_assoc($new)); ?>
      </table>
<?
$content = ob_get_contents();
ob_end_clean();
$f=fo pen('myfile.txt','a');
fwr ite($f,$content);
fcl ose($f);
?>
Save to a php file, then look into Cron Jobs (google it if you need to)
And setup a cron job to run php /path/to/file.php (and some other parameter i cant remember) every 20 min

Wow... odd..


the staff here has some special code that throws 403 forbidden if you try to type code that accesses files...

namely the fw rite code

remove the spaces from the file writing functions.




testing


fputs();

[a href="http://forums.fanetworks.net" target="_blank"][/a]
» faNetworks Webmaster. [[a href="http://fanetworks.net" target="_blank"]fanetworks.net[/a]]
» faSoftware Developer [[a href="http://software.fanetworks.net" target="_blank"]software.fanetworks.net[/a]]
» faForums - php Resource + more [[a href="http://forums.fanetworks.net" target="_blank"]forums.fanetworks.net[/a]]
» Experienced php Coder - Ill help anyone I can if I have time ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users