Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 05:22:58 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155555 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Code module problem if used connection to database  (Read 2543 times)
ZipDriver

Offline Offline

Posts: 5


« on: December 15, 2007, 11:11:21 AM »

Hello,

One question to website baker gurus.

From Code Module try execute php some code. This code is perform the connection to database (not website baker database). All working correctly but after code execute I get a warning message like this:

=============================
Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/user/public_html/framework/class.database.php on line 137

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/user/public_html/framework/class.database.php on line 137

Fatal error: Call to a member function numRows() on a non-object in /home/user/public_html/framework/class.frontend.php on line 337
=============================

In my php code I do not call any functions from wb classes and use only standart php mysql functions. The code example:

=============================
//selected blog site. currently hardcoded one
$website = "blog";
// connect to WordPress database for selected web site
if ($website="blog") {
    $dbwphost = 'localhost';
    $dbwpuser = 'usrWP';
    $dbwppass = 'Mm8p';
    $dbwpname = 'dbWP';
}
$conn = mysql_connect($dbwphost, $dbwpuser, $dbwppass) or die ('Error connecting to database server');
mysql_select_db($dbwpname);
$sql = "select distinct wp_terms.slug, wp_term_taxonomy.ta xonomy, wp_term_taxonomy.co unt from `wp_terms` left join wp_term_taxonomy on wp_terms.`term_id`=wp_term_taxonomy.`term_id` where wp_terms.term_id in (select term_id from wp_term_taxonomy where (taxonomy = 'category' or taxonomy = 'post_tag') and count > 0)";
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
// options list for Category ListBox and Tag ListBox
    if ($row[1] == "category") {
        $catListBox .= "<option value=\"".$row[0]."\">".ucfirst($row[0])." (".$row[2]." posts)</option>";
    } elseif ($row[1] == "post_tag") {
        $tagListBox .= "<option value=\"".$row[0]."\">".ucfirst($row[0])." (".$row[2]." posts)</option>";
    }
}
mysql_close($conn);
=============================

How I need connect to external database to avoide warning message?

Thank you for your ideas and your time in advance.

Regards,
Andrejs.
Logged
pcwacht
Guest
« Reply #1 on: December 15, 2007, 02:04:00 PM »

reset wb database from within php code section after you are done with (not tested) something like
$wb = wb->database;


have fun
John



Logged
ZipDriver

Offline Offline

Posts: 5


« Reply #2 on: December 16, 2007, 09:55:53 AM »

Sorry but completely don't understand about you talking  huh
Logged
thorn

Offline Offline

Posts: 980


WWW
« Reply #3 on: December 16, 2007, 12:55:08 PM »

Hello,

$conn = mysql_connect($dbwphost, $dbwpuser, $dbwppass) or die ('Error connecting to database server');

with PHP >= 4.2.0 try instead:
Code:
$conn = mysql_connect($dbwphost, $dbwpuser, $dbwppass, true) or die ('Error connecting to database server');
Have a look at http://www.php.net/manual/en/function.mysql-connect.php : "new link" for this.

thorn.
Logged

ZipDriver

Offline Offline

Posts: 5


« Reply #4 on: December 17, 2007, 08:11:20 AM »

The same problem with parameter "true".  Non working idea  angry

Currently use error_reporting(0); in first line but sure this is a not ideal way Smiley
Logged
pcwacht
Guest
« Reply #5 on: December 17, 2007, 08:40:39 AM »

Quote
All working correctly but after code execute I get a warning message like this:

I think you mean that your code is running ok and after your code is done you get the errors and warnings??

Or does your code gives the errors?

John

Logged
ZipDriver

Offline Offline

Posts: 5


« Reply #6 on: December 17, 2007, 09:30:18 AM »

Code working without errors. All correct but have above errors after code output.
Logged
pcwacht
Guest
« Reply #7 on: December 17, 2007, 02:10:45 PM »

ok

Your code connects to the db thus ending the connection with the db from wb

Solution, reconnect to the db from within wb right before you leave your code thus restoring all db connections wb need

At the end of your code put:
Code:
   $database = new database();
to restore the db

Think this will do

Have fun,
John
Logged
ZipDriver

Offline Offline

Posts: 5


« Reply #8 on: December 17, 2007, 07:36:06 PM »

John,

Thanks a lot for your help. The last solution working OK. Once again thank you.
I hope my question will be useful for other.

Regards,
Andrejs.
Logged
lanesharon

Offline Offline

Posts: 47


WWW
« Reply #9 on: December 18, 2007, 04:30:57 AM »

Well, you may have already helped out one other person.  Thanks!
Logged

Take Care,  Sharon
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!