Page 1 of 2
mysql part not working
Posted: Fri May 18, 2007 2:45 pm
by zyklon
i have 2 line of code in the ticker for my game not working... i have no idea why, i get no error message at all, here they are:
Code: Select all
mysql_query("SET @i=0");
mysql_query("UPDATE `user` SET `rank`=(@i:=(@i+1)) ORDER BY `power` DESC");
Re: mysql part not working
Posted: Fri May 18, 2007 2:49 pm
by volka
zyklon wrote:i get no error message at all
Maybe because there's no error handling at all in your code.
try
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('mysql.trace_mode', true);
$mysql = mysql_connect(...) or die(mysql_error());
mysl_select_db('...', $mysql) or die(mysql_error());
mysql_query("SET @i=0", $mysql) or die(mysql_error());
mysql_query("UPDATE `user` SET `rank`=(@i:=(@i+1)) ORDER BY `power` DESC", $mysql) or die(mysql_error());
echo 'affected rows: ', mysql_affected_rows($mysql), "<br />\n";
Posted: Fri May 18, 2007 2:53 pm
by zyklon
the only output then was affected rows:0
should i mention this is on php4 and mysql4 ??
Posted: Fri May 18, 2007 3:09 pm
by RobertGonzalez
Is your intent to update the entire table? There is no where clause.
Posted: Fri May 18, 2007 3:10 pm
by zyklon
yup the whole table, it takes all the users and orders them by power, placing the highest power with rank 1 and the second highest rank 2, an so on and so forth.
Posted: Fri May 18, 2007 3:18 pm
by volka
The script works fine with mysql 5. Sorry, I have no mysql 4 at hand for testing.
Posted: Fri May 18, 2007 3:35 pm
by zyklon
there shouldnt be any difference as well between mysql4 and 5 in this area... this is weird... could it be that i have to have my mysql4 working in a certain way, or the db a certain type??
Posted: Fri May 18, 2007 3:40 pm
by volka
Not that I know of.
Please try
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('mysql.trace_mode', true);
$mysql = mysql_connect(...) or die(mysql_error());
mysql_select_db(..., $mysql) or die(mysql_error());
mysql_query("SET @i=0", $mysql) or die(mysql_error());
mysql_query("SET @i=@i+3", $mysql) or die(mysql_error());
$result = mysql_query("SELECT @i", $mysql) or die(mysql_error());
echo mysql_result($result, 0, 0), "<br />\n";
mysql_query("UPDATE `user` SET `rank`=rand()*100 ORDER BY `power` DESC", $mysql) or die(mysql_error());
echo 'affected rows: ', mysql_affected_rows($mysql), "<br />\n";
What does it print?
Posted: Fri May 18, 2007 3:47 pm
by zyklon
it prints:
3
affected rows: 3
and it changed the rankings of the 3 dummy accounts i use to test.
Posted: Fri May 18, 2007 3:58 pm
by volka
Did you add the mysql.trace_mode line? And didn't post all the output?
AOL Speak
Posted: Fri May 18, 2007 3:59 pm
by zyklon
thats exactly what i got and i just pasted what you entered, changed it, so it would work and bam
Posted: Fri May 18, 2007 4:00 pm
by volka
Then you must be using a php version < 4.3.0, right?
Posted: Fri May 18, 2007 4:25 pm
by RobertGonzalez
Help us help you. Run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array('off', 0, false, '', null);
$flags = array(
'Register Globals' => 'register_globals',
'Short Tags' => 'short_open_tag',
'Display Errors' => 'display_errors',
'Magic Quotes GPC' => 'magic_quotes_gpc',
'Magic Quotes Runtime' => 'magic_quotes_runtime',
'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$flags['Config file'] = get_cfg_var('cfg_file_path');
if (empty($flags['Config file']))
{
$flags['Config file'] = '-';
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";
$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . $eol;
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
$e2 = array();
foreach ($ec as $n => $v)
{
if (!in_array($n, $e) and $n != 'E_ALL')
{
$e2[] = $n;
}
}
$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
$er = $er . ' (' . implode(' | ', $e) . ')';
}
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}
echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;
if (!$cli)
{
echo '</pre></body></html>', $eol;
}
?>
Posted: Fri May 18, 2007 9:30 pm
by zyklon
PHP Version: 4.2.2
PHP OS: WINNT
Error Reporting: 2039 ((E_ALL | E_STRICT) ^ E_STRICT ^ E_NOTICE))
Register Globals: Off
Short Tags: On
Display Errors: On
Magic Quotes GPC: On
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Config file: -
Loaded Extensions:
standard bcmath calendar com
ftp mysql odbc pcre
session xml wddx apache
Posted: Sat May 19, 2007 9:18 am
by aaronhall
Is the query doing anything to the table? Perhaps the references to the rank column in other parts of your code are bad.