php-general Digest 6 May 2012 12:54:43 -0000 Issue 7803
Topics (messages 317805 through 317810):
I'm missing something
317805 by: Jim Giner
317806 by: Matijn Woudt
317807 by: Jim Giner
317808 by: Jim Giner
317809 by: Matijn Woudt
PHP Subroutine Call Blowing UP with Strings
317810 by: George R Smith
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
I have a discrepancy in the number of elements in my arrays and can't see
why.
Here is some code:
Note the lines with the ***
*** $plyrs = 0;
unset($plyrnames_ar);
unset($js_names);
unset($js_seeds);
*** $rows = mysql_num_rows($qrslts);
***echo "in mysql there are $rows rows<br>";
while ($row = mysql_fetch_array($qrslts))
{ // build the name value here
$mi = ($row['MI']=='') ? '' : " ".$row['MI'];
$nm = $row['LastName'].", ".$row['FirstName'].$mi;
if ($row['srtdbls']=='X')
{
$mi = ($row['partMI']=='') ? '' : " ".$row['partMI'];
$nm .= "/".$row['partLN'].", ".$row['partFN'].$mi;
}
*** $plyrs++;
$plyrnames_ar[$nm] = $row['Draw_pos'];
}
*** echo "before sort there are ".count($plyrnames_ar)." in
plyrsnames_ar<br>";
ksort($plyrnames_ar);
foreach ($plyrnames_ar as $nm=>$sd)
{
$js_names[] = $nm;
$js_seeds[] = $sd;
}
*** echo "plyrs is $plyrs and there are ".count($js_names)." entries in
js_rnames and ".count
***($plyrnames_ar)." entries in plyrnames_ar and ".count($js_seeds)." in
js_seeds";
exit();
The problem is that my $plyrs field comes up 18, while in truth there are
only 17 rows of data in my database.
All of the other array-size counts echo out as being only 17, but my $rows
and $plyrs fields come up as 18. I was having problems with my javascript
showing an undefined array element and took a bit o time to determine what
it was and where it was happening.
Questions - does mysql_num_rows return a extra row that somehow doesn't get
processed in the while loop? And if it does how come the counter ($plyrs)
that I put into the loop comes up higher than it should.?
--- End Message ---
--- Begin Message ---
On Sun, May 6, 2012 at 12:38 AM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> I have a discrepancy in the number of elements in my arrays and can't see
> why.
>
> Here is some code:
> Note the lines with the ***
>
> *** $plyrs = 0;
> unset($plyrnames_ar);
> unset($js_names);
> unset($js_seeds);
> *** $rows = mysql_num_rows($qrslts);
> ***echo "in mysql there are $rows rows<br>";
> while ($row = mysql_fetch_array($qrslts))
> { // build the name value here
> $mi = ($row['MI']=='') ? '' : " ".$row['MI'];
> $nm = $row['LastName'].", ".$row['FirstName'].$mi;
> if ($row['srtdbls']=='X')
> {
> $mi = ($row['partMI']=='') ? '' : " ".$row['partMI'];
> $nm .= "/".$row['partLN'].", ".$row['partFN'].$mi;
> }
> *** $plyrs++;
> $plyrnames_ar[$nm] = $row['Draw_pos'];
> }
> *** echo "before sort there are ".count($plyrnames_ar)." in
> plyrsnames_ar<br>";
> ksort($plyrnames_ar);
> foreach ($plyrnames_ar as $nm=>$sd)
> {
> $js_names[] = $nm;
> $js_seeds[] = $sd;
> }
> *** echo "plyrs is $plyrs and there are ".count($js_names)." entries in
> js_rnames and ".count
> ***($plyrnames_ar)." entries in plyrnames_ar and ".count($js_seeds)." in
> js_seeds";
> exit();
>
> The problem is that my $plyrs field comes up 18, while in truth there are
> only 17 rows of data in my database.
> All of the other array-size counts echo out as being only 17, but my $rows
> and $plyrs fields come up as 18. I was having problems with my javascript
> showing an undefined array element and took a bit o time to determine what
> it was and where it was happening.
>
> Questions - does mysql_num_rows return a extra row that somehow doesn't get
> processed in the while loop? And if it does how come the counter ($plyrs)
> that I put into the loop comes up higher than it should.?
>
>
My guess would be that you end up with 2 rows having the same $nm,
overwriting the value that's already in $plyrnames_ar.
- Matijn
--- End Message ---
--- Begin Message ---
My guess would be that you end up with 2 rows having the same $nm,
overwriting the value that's already in $plyrnames_ar.
- Matijn
************
Genius at work! Thanks - I'll look into that.
--- End Message ---
--- Begin Message ---
Yup that was it! Something I knew would happen during my design, but forgot
to code for now.
""Jim Giner"" <jim.gi...@albanyhandball.com> wrote in message
news:e2.dc.30075.c6ea5...@pb1.pair.com...
>
>
> My guess would be that you end up with 2 rows having the same $nm,
> overwriting the value that's already in $plyrnames_ar.
>
> - Matijn
> ************
> Genius at work! Thanks - I'll look into that.
>
--- End Message ---
--- Begin Message ---
On Sun, May 6, 2012 at 12:53 AM, Jim Giner <jim.gi...@albanyhandball.com> wrote:
> Yup that was it! Something I knew would happen during my design, but forgot
> to code for now.
>
> ""Jim Giner"" <jim.gi...@albanyhandball.com> wrote in message
> news:e2.dc.30075.c6ea5...@pb1.pair.com...
>>
>>
>> My guess would be that you end up with 2 rows having the same $nm,
>> overwriting the value that's already in $plyrnames_ar.
>>
>> - Matijn
>> ************
>> Genius at work! Thanks - I'll look into that.
>>
Jim,
Two things:
1) You should bottom post on this (probably any) mailing list.
2) You can avoid these errors if you define unique fields in your database.
- Matijn
--- End Message ---
--- Begin Message ---
All,
I am new to PHP (about 3 weeks) and am testing
the return of strings from a external database
subroutine. This database is not relational, not
MySQL, MSSQL or others.
Thanks to all in advance for any help.
Some info which might be helpful:
phpinfo()
PHP Version => 5.3.3-7+squeeze8
System => Linux dellT710 2.6.32-5-amd64
#1 SMP Mon Mar 26 07:00:19 UTC 2012 x86_64
root@dellT710:/var/www# php -i | grep extension_dir
extension_dir => /usr/lib/php5/20090626+lfs => /usr/lib/php5/20090626+lfs
root@dellT710:/usr/lib/php5/20090626+lfs# ls -la
total 812
drwxr-xr-x 2 root root 4096 May 3 20:28 .
drwxr-xr-x 5 root root 4096 May 2 07:35 ..
-rw-r--r-- 1 root root 62936 Feb 10 08:31 curl.so
-rw-r--r-- 1 root root 95596 Feb 10 08:31 gd.so
-rw-r--r-- 1 root root 38272 Feb 10 08:31 mcrypt.so
-rw-r--r-- 1 root root 109220 Feb 10 08:31 mysqli.so
-rw-r--r-- 1 root root 42352 Feb 10 08:31 mysql.so
-rw-r--r-- 1 root root 26116 Feb 10 08:31 pdo_mysql.so
-rw-r--r-- 1 root root 87588 Feb 10 08:31 pdo.so
-rwxr-xr-x 1 root root 173342 May 3 20:28 qmphp.so
-rw-r--r-- 1 root root 141336 Aug 19 2010 suhosin.so
The qmphp.so is the extension that is doing the call.
Written by someone else installed by me.
The subroutine returns 14 characters or less but
blows up when I increase the string to 15 characters.
Here is the successful return of two arguments
and with 14 characters in the second argument.
root@dellT710:/var/www# php test.php
errorMsg
ThereAre14Char
The test code:
<?php
QMConnectLocal("ACCOUNT");
$arg_1 = "10064";
$arg_2 = "ARG";
QMCall("GET.STRING", 2,&$arg_1, &$arg_2);
echo $arg_1;
echo "\n";
echo $arg_2;
echo "\n";
QMDisconnectAll();
When I increase the string size to 15 characters it blows
up:
root@dellT710:/var/www# php qm_get_clients.php
*** glibc detected *** php: free(): invalid next size (fast): 0x0a2c3998 ***
======= Backtrace: =========
/lib/i686/cmov/libc.so.6(+0x6b381)[0xf70d3381]
/lib/i686/cmov/libc.so.6(+0x6cbd8)[0xf70d4bd8]
/lib/i686/cmov/libc.so.6(cfree+0x6d)[0xf70d7cbd]
/usr/lib/php5/20090626+lfs/qmphp.so(zif_QMCall+0x2be)[0xf6cdfdce]
php(execute_internal+0x4b)[0x831eb8b]
/usr/lib/php5/20090626+lfs/suhosin.so(+0x15fa3)[0xf64e7fa3]
php[0x834aa58]
php(execute+0x1ce)[0x832151e]
/usr/lib/php5/20090626+lfs/suhosin.so(+0x16404)[0xf64e8404]
php(zend_execute_scripts+0x66)[0x82f7296]
php(php_execute_script+0x1e4)[0x829b4c4]
php[0x838d84b]
/lib/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xf707eca6]
php[0x806bbc1]
======= Memory map: ========
08048000-0871f000 r-xp 00000000 08:01 9453192 /usr/bi
n/php5
0871f000-0875e000 r--p 006d7000 08:01 9453192 /usr/bi
n/php5
0875e000-08764000 rw-p 00716000 08:01 9453192 /usr/bi
n/php5
08764000-0877b000 rw-p 00000000 00:00 0
0a138000-0a324000 rw-p 00000000 00:00 0 [heap]
f5b00000-f5b21000 rw-p 00000000 00:00 0
f5b21000-f5c00000 ---p 00000000 00:00 0
f5ca7000-f5cc4000 r-xp 00000000 08:01 36003843 /lib/li
bgcc_s.so.1
f5cc4000-f5cc5000 rw-p 0001c000 08:01 36003843 /lib/li
bgcc_s.so.1
f5cc5000-f5cc6000 ---p 00000000 00:00 0
f5cc6000-f64c6000 rwxp 00000000 00:00 0
f64c6000-f64d0000 r-xp 00000000 08:01 36028681 /lib/i6
86/cmov/libnss_files-2.11.3.so
f64d0000-f64d1000 r--p 00009000 08:01 36028681 /lib/i6
86/cmov/libnss_files-2.11.3.so
f64d1000-f64d2000 rw-p 0000a000 08:01 36028681 /lib/i6
86/cmov/libnss_files-2.11.3.so
f64d2000-f64f2000 r-xp 00000000 08:01 9504820 /usr/li
b/php5/20090626+lfs/suhosin.so
f64f2000-f64f6000 rw-p 0001f000 08:01 9504820 /usr/li
b/php5/20090626+lfs/suhosin.so
f64f6000-f64f8000 rw-p 00000000 00:00 0
f64f8000-f64fe000 r-xp 00000000 08:01 9504862 /usr/li
b/php5/20090626+lfs/pdo_mysql.so
f64fe000-f64ff000 r--p 00005000 08:01 9504862 /usr/li
b/php5/20090626+lfs/pdo_mysql.so
f64ff000-f6500000 rw-p 00006000 08:01 9504862 /usr/li
b/php5/20090626+lfs/pdo_mysql.so
f6500000-f6513000 r-xp 00000000 08:01 9503395 /usr/li
b/php5/20090626+lfs/pdo.so
f6513000-f6515000 r--p 00013000 08:01 9503395 /usr/li
b/php5/20090626+lfs/pdo.so
f6515000-f6516000 rw-p 00015000 08:01 9503395 /usr/li
b/php5/20090626+lfs/pdo.so
f6516000-f652e000 r-xp 00000000 08:01 9504863 /usr/li
b/php5/20090626+lfs/mysqli.so
f652e000-f6531000 r--p 00017000 08:01 9504863 /usr/li
b/php5/20090626+lfs/mysqli.so
f6531000-f6532000 rw-p 0001a000 08:01 9504863 /usr/li
b/php5/20090626+lfs/mysqli.so
f6532000-f66e5000 r-xp 00000000 08:01 12943509 /usr/li
b/libmysqlclient_r.so.16.0.0
f66e5000-f66e9000 r--p 001b2000 08:01 12943509 /usr/li
b/libmysqlclient_r.so.16.0.0
f66e9000-f672e000 rw-p 001b6000 08:01 12943509 /usr/li
b/libmysqlclient_r.so.16.0.0
f672e000-f672f000 rw-p 00000000 00:00 0
f672f000-f6738000 r-xp 00000000 08:01 9504864 /usr/li
b/php5/20090626+lfs/mysql.so
f6738000-f673a000 r--p 00008000 08:01 9504864 /usr/li
b/php5/20090626+lfs/mysql.so
f673a000-f673b000 rw-p 0000a000 08:01 9504864 /usr/li
b/php5/20090626+lfs/mysql.so
f673b000-f6742000 r-xp 00000000 08:01 12943513 /usr/li
b/libltdl.so.7.2.1
f6742000-f6743000 rw-p 00007000 08:01 12943513 /usr/li
b/libltdl.so.7.2.1
f6743000-f6768000 r-xp 00000000 08:01 12943526 /usr/li
b/libmcrypt.so.4.4.8
f6768000-f676b000 rw-p 00025000 08:01 12943526 /usr/li
b/libmcrypt.so.4.4.8
f676b000-f6770000 rw-p 00000000 00:00 0
f6770000-f6778000 r-xp 00000000 08:01 9504871 /usr/li
b/php5/20090626+lfs/mcrypt.so
f6778000-f677a000 r--p 00007000 08:01 9504871 /usr/li
b/php5/20090626+lfs/mcrypt.so
f677a000-f677b000 rw-p 00009000 08:01 9504871 /usr/li
b/php5/20090626+lfs/mcrypt.so
f677b000-f677f000 r-xp 00000000 08:01 9451699 /usr/li
b/libXdmcp.so.6.0.0
f677f000-f6780000 rw-p 00003000 08:01 9451699 /usr/li
b/libXdmcp.so.6.0.0
f6780000-f6782000 r-xp 00000000 08:01 9451697 /usr/li
b/libXau.so.6.0.0
f6782000-f6783000 rw-p 00001000 08:01 9451697 /usr/li
b/libXau.so.6.0.0
f6783000-f67a7000 r-xp 00000000 08:01 9446554 /usr/li
b/libexpat.so.1.5.2
f67a7000-f67a9000 rw-p 00023000 08:01 9446554 /usr/li
b/libexpat.so.1.5.2
f67a9000-f67c1000 r-xp 00000000 08:01 9451701 /usr/li
b/libxcb.so.1.1.0
f67c1000-f67c2000 rw-p 00017000 08:01 9451701 /usr/li
b/libxcb.so.1.1.0
f67c2000-f67ef000 r-xp 00000000 08:01 12943437 /usr/li
b/libfontconfig.so.1.4.4
f67ef000-f67f1000 rw-p 0002c000 08:01 12943437 /usr/li
b/libfontconfig.so.1.4.4
f67f1000-f6810000 r-xp 00000000 08:01 9450805 /usr/li
b/libjpeg.so.62.0.0
f6810000-f6811000 rw-p 0001e000 08:01 9450805 /usr/li
b/libjpeg.so.62.0.0
f6811000-f6834000 r-xp 00000000 08:01 36004292 /lib/li
bpng12.so.0.44.0
f6834000-f6835000 rw-p 00022000 08:01 36004292 /lib/li
bpng12.so.0.44.0
f6835000-f6844000 r-xp 00000000 08:01 12943524 /usr/li
b/libXpm.so.4.11.0
f6844000-f6845000 rw-p 0000e000 08:01 12943524 /usr/li
b/libXpm.so.4.11.0
f6845000-f695e000 r-xp 00000000 08:01 9451705 /usr/li
b/libX11.so.6.3.0
f695e000-f6962000 rw-p 00118000 08:01 9451705 /usr/li
b/libX11.so.6.3.0
f6962000-f69d6000 r-xp 00000000 08:01 9450803 /usr/li
b/libfreetype.so.6.6.0
f69d6000-f69da000 rw-p 00073000 08:01 9450803 /usr/li
b/libfreetype.so.6.6.0
f69da000-f6a16000 r-xp 00000000 08:01 12943529 /usr/li
b/libt1.so.5.1.2Aborted
root@dellT710:/var/www#
thanks again
george
--- End Message ---