PDA

View Full Version : mysql query sometime return nothing in widgets


dimiandre
02-28-2012, 06:16 PM
hi all,
i have added a new widget in my vbulletin cms. It's a "direct execution widget"

in it i have an Mysql query that return counts of some rows in my database..

but sometimes it returns nothing :S

i have tryed to run the query manually from "phpmyadmin" and the query itself works

this is the code of my widget:
require_once("mysql_vars.php");
$conn_widget = mysql_connect($host, $user, $pass);
mysql_select_db($characters, $conn_widget);
$result_wid = mysql_query("SELECT Count(Online) FROM `characters` WHERE `online` = 1", $conn_widget);
$row_wid = mysql_fetch_array($result_wid);
$online_wid = $row_wid["Count(Online)"];

if (!$sock = @fsockopen("127.0.01", 8085, $errno, $errstr, 30))
$output = '<div class="status">Server Status: <FONT COLOR="#ff1f1f">OFF</FONT></div>';
else
{
$output = '<div class="status">Server Status: <FONT COLOR="#3acc3a">ON</FONT></div>';
fclose($sock);
}

$output .= '<div class="status"> PG Online: <font color="#c9c9c9">';
$output .= $online_wid;
$output .= '</font></div>';

mysql_close($conn_widget);


sometimes "$online_wid" return nothing, some help ?

maybe cache problem ? :S

i have the same problem with similar widgets that should return data from an database..
thanks, i'm using vbulletin 4.1.10

kh99
02-28-2012, 06:38 PM
You could try checking the return values of your mysql calls and in the case of an error, call mysql_error() to get the details. For instance, the example code on this page: http://us2.php.net/manual/en/function.mysql-connect.php shows how it could be done for mysql_connect (although you probably don't want to call die() in your widget).

dimiandre
02-28-2012, 07:05 PM
changed in:

code removed


and when problems happend it don't give me any error :(

edit, ok now it give me the error:
Errore!: Access denied for user 'www'@'localhost' (using password: NO)
but obviously www it's not the same username of $user, it's the linux account where apache is running :S

edit2: if i try to put directly mysql account informations in mysql_connect($host, $user, $pass);
with "mysql_connect(127.0.0.1, "XXX", "XXX");"
sometimes it works, and sometimes the widget closes on himself like this screen:
http://img62.imageshack.us/img62/4190/immaginepmx.png
http://img828.imageshack.us/img828/2008/immagine2zw.png

dimiandre
03-01-2012, 08:45 AM
up

please, the problem isn't solved

kh99
03-01-2012, 12:31 PM
I don't see anything wrong (although I could be missing something of course), but if it's blank sometimes that seems to mean that something is causing an error, but only sometimes. I don't know why the query would sometimes return nothing.

Maybe try putting in a line like:

$output .= "1"; return;


start with it right under the reuqire once. If it always works (just shows "1"), then move it down a line and try again. When (if) you get to a point where the problem starts happening, you'll know it's caused by the line above.

dimiandre
03-05-2012, 02:11 PM
hum i have solved using file() to grab data from an external php file instead of queryng the server

in this way all works perfect :P

thanks