Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2

Author Topic: mysql_connection conflict?  (Read 8598 times)

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« on: July 25, 2007, 10:34:59 PM »

Hi all, I'm running sNews 1.5.31 on this web site here.   http://cssdreams.com/

And then made a call to an include of the "simple download counter" which can be downloaded here.  http://www.neoprogrammers.com/

It's basically just a script which counts each time a file is downloaded and increments that number in a DB, pretty simple.  The problem is that it seems after I include download.php the rest of the sNews items which are pulled from a different DB are no longer referenced on the page!  

View here:
http://www.cssdreams.com/residuals/starcraft/

Anyone have any clues as to why,  or what I can do to prevent this?

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
mysql_connection conflict?
« Reply #1 on: July 26, 2007, 05:52:06 AM »

1) are both databases yours to control??
2) do you have an identical setup on your comp??
--2a) if so, does the same occur?

try adding the following before the closing php tag   ( ?> ) in download.php

connect_to_db()

That should reselect the snews db that was disconnected?? in download.php.

I think.
Logged
Of all the things I have lost, it is my mind that I miss the most.

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #2 on: July 26, 2007, 09:22:01 AM »

1. Yes.

2. No, I don't setup my DB locally usually. Rarely any need to do so, for me.

And btw, your suggestion worked. I love you!  :D

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
mysql_connection conflict?
« Reply #3 on: July 26, 2007, 09:35:28 AM »

Um....  :P
Logged
Of all the things I have lost, it is my mind that I miss the most.

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #4 on: July 26, 2007, 10:34:32 AM »

One more question. I've now got the entire list of links called from an include. But they are supposed to display the count of each download. My MySQL DB is keeping records of the downloads, so that part works, but its not displaying it on the page.  And I'm not sure whats preventing it from displaying,  here's the function:

http://www.cssdreams.com/residuals/starcraft/

Code: [Select]
function showCount($fileID)
{
global $cnt_sql;
$query = "SELECT count FROM dl_count WHERE file = '$fileID'";
$result = mysql_query($query, $cnt_sql);
if(mysql_num_rows($result) == 0) {
   return 0;
} else {
$count = mysql_fetch_row($result);
return $count[0];
}

}
And its called like:
Code: [Select]
Obviously the problem is this line:  if(mysql_num_rows($result) == 0)  but what I dont get is, WHY isn't the script able to see the DB results?  And howcome it isn't throwing an error?

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #5 on: July 26, 2007, 10:39:08 AM »

Hmm, looks like error_reporting(0); inside of snews.php was keeping the errors hidden.

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
mysql_connection conflict?
« Reply #6 on: July 26, 2007, 10:54:57 AM »

It's throwing warning all over Your page ;)

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/cssdream/public_html/download.php on line 134

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/cssdream/public_html/download.php on line 135

I assume that reconnection to sNews at the end of download script might be guilty for this. You should manage reconnections outside include otherwise it's not going to work nice IMHO.
Logged

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #7 on: July 26, 2007, 11:03:15 AM »

Well, atleast its good to see that I'm not the only one up at 2AM tackling this :)

*sigh* If it's going to be that complicated I may as well forget about it.

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
mysql_connection conflict?
« Reply #8 on: July 26, 2007, 11:35:06 AM »

But U are, You know, mike ;) I mean for me it's like 12:30AM :P
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
mysql_connection conflict?
« Reply #9 on: July 26, 2007, 11:38:29 AM »

And You have almost done it, it's just about wrapping up some lose ends ;)
Logged

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #10 on: July 26, 2007, 05:52:34 PM »

Yeah I know, but I don't really wish to hackup sNews anymore than it needs to be. I may want to use this script on multiple sNews sites....  perhaps an iframe would do the trick?  I can keep the seperate MySQL connection in a seperate page.

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #11 on: July 26, 2007, 07:35:22 PM »

Looks like sNews doesn't like iframes....  I'm going to try to insert it via the DB.

michael kennedy

  • Full Member
  • ***
  • Karma: 3
  • Posts: 207
    • SpektreDesign
mysql_connection conflict?
« Reply #12 on: July 26, 2007, 08:23:52 PM »

That did the trick.  I think for future versions of sNews allowing us to quickly insert [iframe]file.php[/iframe]  would be useful to have.

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
mysql_connection conflict?
« Reply #13 on: July 26, 2007, 09:04:44 PM »

Solution's been found, so, cheers  :)
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
mysql_connection conflict?
« Reply #14 on: July 27, 2007, 01:33:42 AM »

hang on... that is probably not necessary.
try this (without your iframes) -- this part of the download.php.
What I have hope to have done is to ensure that the dbase is selected as it is required.
YMMV
Quote
//CONFIGURATION SECTION

$FILES_DIR = "/downloads/";
//URI to files
//Include beginning and trailing slash
//This is the web path to your files, not a server path
//Example:  www.yoursite.com/folder/files/ will be /folder/files/
//If you wish to serve offsite files, you can use http://www.site.com/downloads/

$MYSQL_USER = "drew";             //The username used to connect to MySQL
$MYSQL_PASS = "password";         //The MySQL Password for the user
$MYSQL_HOST = "localhost";        //The host to connect to
$MYSQL_DB   = "drew";             //The database in which the dl_count table is in


##############################################################
# Thats IT!!  No more configuration required.
##############################################################


$cnt_sql = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASS);
@mysql_select_db($MYSQL_DB, $cnt_sql);

if(isset($_GET['file'])) {
   $file = urlencode($_GET['file']);

   if(empty($file)) {
      echo "No File Specified";
      exit;
   }
   if(strpos($file, "..") !== FALSE) {
      echo "HACK ATTEMPT!";
      exit;
   }
   if(strpos($file, "://") !== FALSE) {
      echo "Invalid File";
      exit;
   }

   $cookie = urlencode(str_replace(".", "_", $file));  //cookie fix

   $query = "SELECT * FROM dl_count WHERE file = '$file'";
   $result = mysql_query($query, $cnt_sql);
   if(!$result) {
      echo mysql_error();
      exit;
   }
   if(mysql_num_rows($result) == 0) {
      //first use of this file
      $query = "INSERT INTO dl_count VALUES('$file', 1)";
      $result = mysql_query($query, $cnt_sql);
      setcookie("dl_" . $cookie, "set", time() + 60*60*24*365);
   } else {
      if(!isset($_COOKIE['dl_' . $cookie])) {
         $query = "UPDATE dl_count SET count = count + 1 WHERE file = '$file'";
         $result = mysql_query($query);
         setcookie("dl_". $cookie, "set", time() + 60*60*24*365);
      }
   }

   header("Location: " . $FILES_DIR . $file);
}

function showCount($fileID)
{
   global $cnt_sql;
   @mysql_select_db($MYSQL_DB, $cnt_sql);
   $query = "SELECT count FROM dl_count WHERE file = '$fileID'";
   $result = mysql_query($query, $cnt_sql);
   if(mysql_num_rows($result) == 0) {
      return 0;
   } else {
      $count = mysql_fetch_row($result);
      return $count[0];
   }
}
@mysql_select_db(db('dbname')) or die(db('dberror'));
?>
Logged
Of all the things I have lost, it is my mind that I miss the most.
Pages: [1] 2