vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Automatically closing threads (https://vborg.vbsupport.ru/showthread.php?t=68244)

hurrican 08-12-2004 02:26 AM

Automatically closing threads
 
I Currently am working with this PHP Script to close threads older than a year, but I can't seem to get it to work, on my command line, I can type
php closethreads.php and it goes on w/o error, but the threads don't lock.. I constructed this with a little bit of other codes i've found on here.. Any help is greatly appreciated!

PHP Code:

$DB_site->query("UPDATE thread
                 SET open = 0
                 WHERE dateline < "
.(TIMENOW - (60 60 24 364))."
                  AND forumid IN (3,4,5)
"
);
?> 


Modin 08-12-2004 03:08 AM

hmm...

I assume you've included global.php etc?

can you post the entire script, maybe it's something earlier in it because that query looks great to me.

If your admin set error reporting to none by default then it wouldn't show any errors. My admin did that once...worst developing environment ever.

hurrican 08-12-2004 03:13 AM

OOpsie, Thanks for the reply! I thought I had copied the whole script, but guess not, lol.. I run my own server, so I can luckily configure everything needed for debugging. I should mention this is for vB2.3.5 - Here's what my entire script looks like.. :classic:

PHP Code:

<?php
require("./global.php");
$DB_site->query("UPDATE thread
                 SET open = 0
                 WHERE dateline < "
.(TIMENOW - (60 60 24 364))."
                     AND forumid IN (3,4,5)
"
);
?>


Modin 08-12-2004 03:20 AM

hmm... maybe global.php won't let you use it outside of a browser... try this instead.


PHP Code:

<?php

$db 
mysql_connect($db_server$db_user$db_pass) or 
        die(
"Could not connect to database with error (".mysql_error().")");

$db_sel mysql_select_db($db_name$db) or 
        die(
"Could not select database $db_name with error (".mysql_error().")");        
        
mysql_query("UPDATE thread SET open = 0 WHERE dateline < ".(TIMENOW - (60 60 24 364))." AND forumid IN (3,4,5)"$db);        
?>

(replacing the necessary variables with your database info of course ;))

hurrican 08-12-2004 03:48 AM

Hmm.. Still no go :( That code is definately a lot better looking though. It's definitely got me baffled, lol.. I really appreciate your help!! :) :) I'm learning the way around MySQL pretty good, but not quite well enough, lol :)

PHP Code:


<?php

$db 
mysql_connect('localhost''un''pw') or
        die(
"Could not connect to database with error (".mysql_error().")");

$db_sel mysql_select_db('dbname'$db) or
        die(
"Could not select database $db_name with error (".mysql_error().")");

mysql_query("UPDATE thread SET open = 0 WHERE dateline < ".(TIMENOW - (60 60 24 364))." AND forumid IN (3,4,5)"$db);
?>

There is still no output below.. hmm
Code:

[root@ball vb]# php closethreads.php

[root@ball vb]#


Natch 08-12-2004 03:51 AM

There will be no output unless you echo something out ...

Modin 08-12-2004 04:32 AM

yeah, there shouldn't be output with that script, though it should update your database.

at the end of it if you want confirmation then add the line. Or whatever you want it to say:)
Code:

echo "Script Completed";

hurrican 08-12-2004 04:46 AM

I did do that just to confirm, but for some weird reason, the threads still don't get closed. I'm baffled, lol. If I go look in phpMySQLadmin the real old threads still all show 1 (open) so I did a search for 0, and they were threads that were already closed.. Any possible suggestions as to why nothing will update??

thanks again, i'll check back in the morning! :)

Modin 08-12-2004 04:55 AM

whooops...

here try this instead :)

PHP Code:

<?php

$db 
mysql_connect('localhost''un''pw') or
        die(
"Could not connect to database with error (".mysql_error().")");

$db_sel mysql_select_db('dbname'$db) or
        die(
"Could not select database $db_name with error (".mysql_error().")");

mysql_query("UPDATE thread SET open = 0 WHERE dateline < ".(time() - (60 60 24 364))." AND forumid IN (3,4,5)"$db);
?>


Dean C 08-12-2004 08:06 AM

If you're using vB3 take a look at one of the files in the includes/cron directory. Put your script you have at the top in a new file in that directory. And add it as a scheduled task :)


All times are GMT. The time now is 11:14 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01343 seconds
  • Memory Usage 1,752KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete