You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 72 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - DB Connection problem in module [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
marsupillami
Private
Private


Joined: May 01, 2003
Posts: 42


PostPosted: Mon Aug 25, 2003 6:28 am Reply with quoteBack to top

Hey, Iīm having a problem. Iīm constructing a poll block, but first Iīm trying to make it as a module. I installed a poll script in my webspace, and it works perfectly

You can see it right here.

This script has more that one page
-Poll.php which has only the following code:

Code:
<?php

require '/home/oc-zone/public_html/modules/Poll/booth.php';
 
newest_booth(1);

?>



The booth.php, where everything is made, and a config.php, which as all the db connection info (it is in require_once at booth.php).

Common.php, which as more code for poll generation.

So, I changed this page to a module, so that I could see header, footer, menus, etc, and coded it this way:

Code:

<?php
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {

    die ("You can't access this file directly...");

}

require_once("mainfile.php");

$module_name = basename(dirname(__FILE__));

include("header.php");

OpenTable();

require '/home/oc-zone/public_html/modules/Poll/booth.php';
 
newest_booth(1);

CloseTable();

include("footer.php");

?>


... keeping all the directories as they were, and Iīm given this error:

Quote:

Warning: mysql_connect(): Access denied for user: 'nobody@localhost' (Using password: NO) in /home/oc-zone/public_html/modules/Poll/common.php on line 203
Unable to connect to the database!


Here goes the function with error:

Code:


   function symp_connect() {
      global $s_dbhost, $s_dbuser, $s_dbpass, $s_dbname;
      global $s_dbid, $s_dbnum;
      if($s_dbid && $s_dbnum > 0) {
         $s_dbnum = $s_dbnum + 1;
      } else {
         if($s_dbuser == "" && $s_dbpass == "") {
            $s_dbid = mysql_connect($s_dbhost);
         } else if($s_dbpass == "") {
            $s_dbid = mysql_connect($s_dbhost, $s_dbuser);
         } else {
            $s_dbid = mysql_connect($s_dbhost, $s_dbuser, $s_dbpass);
         }
         if(!$s_dbid || !mysql_select_db($s_dbname, $s_dbid)) {
            die("Unable to connect to the database!\n");
         }
         $s_dbnum = 1;
      }
   }



So, anybody could help me solve the problem? I canīt understand whi this happens, since it works perfetcly as a non-module.

Thankx for any help
Find all posts by marsupillamiView user's profileSend private messageVisit poster's website
Hadron
Corporal
Corporal


Joined: Aug 20, 2003
Posts: 61


PostPosted: Mon Aug 25, 2003 9:25 am Reply with quoteBack to top

If this is a module why are you writing your own db connection function when nuke has already made a connection? Just use the existing one. If you are inside of a function just make sure to "global $db" inside that function and use the sql abstraction layer already written for you.

--Hadron
Find all posts by HadronView user's profileSend private message
marsupillami
Private
Private


Joined: May 01, 2003
Posts: 42


PostPosted: Mon Aug 25, 2003 11:07 am Reply with quoteBack to top

It is because I donīt know how to do that. Hereīs an example of a function that demands a connection:

Code:
   function symp_poll_fetch($pid) {
      global $s_dbid, $SYMP_REMOTE_ADDR, $s_blength, $s_iplog, $s_cookielog,
      $sympvotes, $s_srand, $S_VIEW_HIDDEN, $S_VIEW_OPEN, $S_VIEW_CLOSED;

      symp_connect();

      /* -1 = random poll
       * -2 = latest poll
       * -3 = nonexistant
       */

      if($pid == -1) {
         $q1 = "SELECT pid FROM sympoll_list WHERE (status & '$S_VIEW_OPEN')";
         $r1 = mysql_query($q1, $s_dbid);
         if(!isset($s_srand)) {
            srand((double) microtime() * 1000000);
            $s_srand = TRUE;
         }
         $pid = mysql_result($r1, rand(0, mysql_num_rows($r1) - 1), 'pid');
      } else if($pid == -2) {
         $q2  = "SELECT pid FROM sympoll_list WHERE (status & '$S_VIEW_OPEN') ORDER BY ";
         $q2 .= "timeStamp DESC LIMIT 1";
         $r2 = mysql_query($q2, $s_dbid);
         $a2 = mysql_fetch_array($r2);
         $pid = $a2['pid'];
      }


So, first of all I would have to delete de symp_connect ();. I didi it, and got this error:

Quote:


Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/oc-zone/public_html/modules/Poll/common.php on line 262

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/oc-zone/public_html/modules/Poll/common.php on line 263

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/oc-zone/public_html/modules/Poll/common.php on line 269

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/oc-zone/public_html/modules/Poll/common.php on line 271



Thanks for any help.
Find all posts by marsupillamiView user's profileSend private messageVisit poster's website
Hadron
Corporal
Corporal


Joined: Aug 20, 2003
Posts: 61


PostPosted: Mon Aug 25, 2003 12:47 pm Reply with quoteBack to top

Quote:
So, I changed this page to a module, so that I could see header, footer, menus, etc, and coded it this way:


Rather than "require" your code, why not just copy paste it into that section? That would be my suggestion. Regardless, you can still do the following:

Code:

function symp_poll_fetch($pid) {
      global $db, ...other variables here...
if($pid == -1) {
  $q1 = "SELECT pid FROM sympoll_list....";
  $r1 = $db -> sql_query($q1);
  .....
  list($pid) = $db -> sql_fetchrow($q1);
  ....
  $r2 = $db -> sql_query($q2);
  $a2 = $db -> sql_fetchrowset($r2);
  $pid = $a2['pid];
  ....
}


See how I "globaled" the $db resource connection? Now just use that and nuke's sql layer:

Code:

$result = $db -> sql_query($query);
$numrows = $db -> sql_numrows($result);
$affected = $db -> sql_affectedrows($result);
$numfields = $db -> sql_numfields($result);
list($var) = $db -> sql_fetchrow($result);
$var_array = $db -> sql_fetchrowset($result);


--Hadron
Find all posts by HadronView user's profileSend private message
marsupillami
Private
Private


Joined: May 01, 2003
Posts: 42


PostPosted: Thu Aug 28, 2003 5:10 am Reply with quoteBack to top

Sorry, but I didnīt understand.

Meanwhile, I fixed some problems in mainfile.php, that were the cause of the failure in mysql connection, and tried again to fix the module, and now the module works perfectly. However, I wanīt to use it as a block, not a module, and I thought that it should work, as it must be the same. However, when I tried to amke it work as a block, I got the mysql problem. Changed the variables in common.php, that were the cause of the failure in connection (instead of requiring config.php, it gets the variables directly), and now I get no error, and says that I have an empty block.

How should I put this?

Code:


<?php

if (eregi("block-Poll.php", $PHP_SELF)) {
    Header("Location: index.php");
    die();
}

require '/home/oc-zone/public_html/blocks/booth.php';
 
newest_booth(1)


?>




Thank you for your replies Hadron. Wink
Find all posts by marsupillamiView user's profileSend private messageVisit poster's website
marsupillami
Private
Private


Joined: May 01, 2003
Posts: 42


PostPosted: Thu Aug 28, 2003 5:28 am Reply with quoteBack to top

Just found out one thing. The problem I thought that was from mainfile.php, was not. The problem is that poll, that closes the mysql connection at the end. Because of that, I was receiving mysql errors. The only way is how you told me.... using the same mysql connection. Could you please explain it better to me? Or if there is a tutorial on the web, could you please tell me where?

Thankx for the help Smile
Find all posts by marsupillamiView user's profileSend private messageVisit poster's website
Hadron
Corporal
Corporal


Joined: Aug 20, 2003
Posts: 61


PostPosted: Thu Aug 28, 2003 7:18 am Reply with quoteBack to top

Do you "echo" your html content out or do you place it in a $content variable? It should be $content for a block.

Other than that, I'd have to see booth.php to do much else.

--Hadron
Find all posts by HadronView user's profileSend private message
marsupillami
Private
Private


Joined: May 01, 2003
Posts: 42


PostPosted: Thu Aug 28, 2003 8:04 am Reply with quoteBack to top

For blocks, I use $content varuabel, and I tried to put that inside a $content ".... "; and no go Sad It would echo the newest_booth (1)
Find all posts by marsupillamiView user's profileSend private messageVisit poster's website
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by · TOGETHER TEAM srl ITALY http://www.togetherteam.it · DONDELEO E-COMMERCE http://www.DonDeLeo.com
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.223 Seconds - 292 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::