Jump to content

Write output of Database Query to file


Kronos9326

Recommended Posts

[code]<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>[/code]

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.
Link to comment
Share on other sites

[!--quoteo(post=362112:date=Apr 5 2006, 10:15 PM:name=DrDre)--][div class=\'quotetop\']QUOTE(DrDre @ Apr 5 2006, 10:15 PM) [snapback]362112[/snapback][/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.
Link to comment
Share on other sites

[code]<?
//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);
?>
[/code]
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();
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.