Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-18 Thread Vinny Gullotta
Thanks all, I appreciate the follow ups and the help with the code. I'm 
still relatively new with this stuff, and never had any formal training, 
it's all just been learn as I go, and I have to learn fast as this project 
is relatively urgent to get completed. I plan on going through all of my 
code on all of these pages and cleaning it up at the end to make it more 
efficient, so I will use these tips to help do that.


Thanks again to all who helped troubleshoot this. It is working great now 
and I think my bosses will be happy. =D



Nathan Rixham [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

learn something new every day! cheers Micah :)

Micah Gersten wrote:

While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Nathan Rixham wrote:

6:  vs '
when you use  php will parse the enclosed string for variables, when
you use ' it won't; so ' leads for faster code, and also encourages
you to code strongly by closing strings and concatenating variables.
Further it allows you to use valid html  around attributes rather
than the invalid '

7: , vs .
there is no vs :) to concatenate we use . (period) not , (comma)

so for 6  7..
echo 'td' . $i['servername'] . '/td';

I'm going to stop there, hope it helps a little bit; and I won't go
any further as half the fun is learning; so you finding out how to
save time on queries and write your own db handlers etc is not my
domain I reckons

Regards

nathan




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Micah Gersten
While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Nathan Rixham wrote:

 6:  vs '
 when you use  php will parse the enclosed string for variables, when
 you use ' it won't; so ' leads for faster code, and also encourages
 you to code strongly by closing strings and concatenating variables.
 Further it allows you to use valid html  around attributes rather
 than the invalid '

 7: , vs .
 there is no vs :) to concatenate we use . (period) not , (comma)

 so for 6  7..
 echo 'td' . $i['servername'] . '/td';

 I'm going to stop there, hope it helps a little bit; and I won't go
 any further as half the fun is learning; so you finding out how to
 save time on queries and write your own db handlers etc is not my
 domain I reckons

 Regards

 nathan


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Nathan Rixham

learn something new every day! cheers Micah :)

Micah Gersten wrote:

While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Nathan Rixham wrote:

6:  vs '
when you use  php will parse the enclosed string for variables, when
you use ' it won't; so ' leads for faster code, and also encourages
you to code strongly by closing strings and concatenating variables.
Further it allows you to use valid html  around attributes rather
than the invalid '

7: , vs .
there is no vs :) to concatenate we use . (period) not , (comma)

so for 6  7..
echo 'td' . $i['servername'] . '/td';

I'm going to stop there, hope it helps a little bit; and I won't go
any further as half the fun is learning; so you finding out how to
save time on queries and write your own db handlers etc is not my
domain I reckons

Regards

nathan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Chris



1: SQL
in mysql queries /should/ use backticks (`) around database, table and 
column names, stop's them getting confused with variables or reserved 
words (like timestamp) and saves you future trouble :)


.. which is a mysql-ism - no other database supports this. As soon as 
you need to use another db (regardless of whether it's this application 
or not), you're stuffed.


For reserved word column names, you don't have much choice but don't do 
that in the first place ;)


http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Other db's will have a similar list - though in most cases, if it's a 
function or sql keyword (eg 'table'), it'll be reserved in all.


further, you'll be needing to use AS to turn COUNT(steps) into a nice 
name like stepcount


Which is also a mysql-ism. Most other db's don't let you use aggregate 
aliases in an order by clause (I think because the sql standard says 
don't do that).


--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-INSTALL] MySQL connector installation/upgrade problems

2007-10-23 Thread David Christopher Zentgraf

On  23. Oct 2007, at 20:33, Colin Guthrie wrote:


If you compile PHP and it finds v3 of mysql that means that you must
have the old development libraries for mysql 3 installed in some
capacity (I believe).

What is the output of:
rpm -qa --nosignature --nodigest | grep -i mysql

This should give some clues.


$ rpm -qa --nosignature --nodigest | grep -i mysql
MySQL-server-community-5.0.45-0.rhel3
mod_auth_mysql-20030510-2.ent
MySQL-shared-compat-5.0.45-0.rhel3
MySQL-client-community-5.0.45-0.rhel3
mysql-bench-3.23.58-16.RHEL3.1
MySQL-python-0.9.1-6
libdbi-dbd-mysql-0.6.5-5
perl-DBD-MySQL-2.1021-4.EL3
qt-MySQL-3.1.2-17.RHEL3
php-mysql-4.3.2-43.ent
MySQL-devel-community-5.0.45-0.rhel3

Now I'm even more confused, the 5.0.45 devel package *is* there.

I would imagine (don't know) that PHP would use the mysql_config  
program

to work out which mysql is installed and get the relevent cflags and
linking options. For me this is provided by the
MySQL-devel-community-5.0.27 package from MySQL... Is this definitely
installed?


$ mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
--cflags [-I/usr/include/mysql -g -pipe -march=i386 - 
mcpu=i686]

--include[-I/usr/include/mysql]
--libs   [-L/usr/lib/mysql -lmysqlclient -lz -lcrypt  
-lnsl -lm]
--libs_r [-L/usr/lib/mysql -lmysqlclient_r -lz - 
lpthread -lcrypt -lnsl -lm -lpthread]

--socket [/var/lib/mysql/mysql.sock]
--port   [3306]
--version[5.0.45]
--libmysqld-libs [-L/usr/lib/mysql -lmysqld -lz -lpthread - 
lcrypt -lnsl -lm -lpthread -lrt]


Doing a simple ls -l on both /usr/lib/mysql and /usr/include/mysql  
shows me that all libraries in there are from Jul 5th, which is too  
old to be my recent MySQL install. So these seem to be the files that  
need updating. Which package will do that for me?


Chrs,
Dav

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-INSTALL] MySQL connector installation/upgrade problems

2007-10-23 Thread Colin Guthrie
David Christopher Zentgraf wrote:
 On  23. Oct 2007, at 20:33, Colin Guthrie wrote:
 
 If you compile PHP and it finds v3 of mysql that means that you must
 have the old development libraries for mysql 3 installed in some
 capacity (I believe).

 What is the output of:
 rpm -qa --nosignature --nodigest | grep -i mysql

 This should give some clues.
 
 $ rpm -qa --nosignature --nodigest | grep -i mysql
 MySQL-server-community-5.0.45-0.rhel3
 mod_auth_mysql-20030510-2.ent
 MySQL-shared-compat-5.0.45-0.rhel3
 MySQL-client-community-5.0.45-0.rhel3
 mysql-bench-3.23.58-16.RHEL3.1
 MySQL-python-0.9.1-6
 libdbi-dbd-mysql-0.6.5-5
 perl-DBD-MySQL-2.1021-4.EL3
 qt-MySQL-3.1.2-17.RHEL3
 php-mysql-4.3.2-43.ent
 MySQL-devel-community-5.0.45-0.rhel3
 
 Now I'm even more confused, the 5.0.45 devel package *is* there.

Yeah that looks pretty OK to me (tho' not overly knowledgeable with
Fedora/Centos packaging)

 I would imagine (don't know) that PHP would use the mysql_config program
 to work out which mysql is installed and get the relevent cflags and
 linking options. For me this is provided by the
 MySQL-devel-community-5.0.27 package from MySQL... Is this definitely
 installed?
 
 $ mysql_config
 Usage: /usr/bin/mysql_config [OPTIONS]
 Options:
 --cflags [-I/usr/include/mysql -g -pipe -march=i386
 -mcpu=i686]
 --include[-I/usr/include/mysql]
 --libs   [-L/usr/lib/mysql -lmysqlclient -lz -lcrypt
 -lnsl -lm]
 --libs_r [-L/usr/lib/mysql -lmysqlclient_r -lz -lpthread
 -lcrypt -lnsl -lm -lpthread]
 --socket [/var/lib/mysql/mysql.sock]
 --port   [3306]
 --version[5.0.45]
 --libmysqld-libs [-L/usr/lib/mysql -lmysqld -lz -lpthread
 -lcrypt -lnsl -lm -lpthread -lrt]
 
 Doing a simple ls -l on both /usr/lib/mysql and /usr/include/mysql shows
 me that all libraries in there are from Jul 5th, which is too old to be
 my recent MySQL install. So these seem to be the files that need
 updating. Which package will do that for me?

No, I reckon Jul 5th could be about right when was .45 released? I
had it in my head it was august but Jul doesn't seem too far before that
so entirely possible.

Use rpm -qf filename to see which package owns which files.

you can also use rpm -V pck to verify that the package has not be
modified on disk.

Does PHP 4 perhaps come with it's own mysql library in the source?
Perhaps you have to pass an argument?

Try using something like: --with-mysql=shared,/usr in the configure to
PHP. That's certainly how I configure PHP5. The args for 4 may be
different tho'.

Col.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-INSTALL] MySQL connector installation/upgrade problems

2007-10-23 Thread David Christopher Zentgraf

On  23. Oct 2007, at 21:07, Colin Guthrie wrote:


No, I reckon Jul 5th could be about right when was .45 released? I
had it in my head it was august but Jul doesn't seem too far before  
that

so entirely possible.


Ah sorry, I was thinking about source installs. RPMs keep the  
original creation date I guess. Not overly used to that.



Use rpm -qf filename to see which package owns which files.


Probing two random files in include/mysql and and lib/mysql show they  
belong to MySQL-devel-community-5.0.45-0.rhel3.



you can also use rpm -V pck to verify that the package has not be
modified on disk.


$ rpm -V MySQL-devel-community-5.0.45-0.rhel3
missing  d /usr/share/man/man1/comp_err.1.gz
missing  d /usr/share/man/man1/mysql_config.1.gz

I suppose this is, albeit not ideal, tolerable?


Does PHP 4 perhaps come with it's own mysql library in the source?
Perhaps you have to pass an argument?


Yes, as of PHP4 the --with-mysql is on by default. I tried specifying  
--with-mysql-dir=/usr and also shared,/usr, but to no avail.


Chrs,
Dav

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-INSTALL] MySQL connector installation/upgrade problems

2007-10-23 Thread Colin Guthrie
David Christopher Zentgraf wrote:
 $ rpm -V MySQL-devel-community-5.0.45-0.rhel3
 missing  d /usr/share/man/man1/comp_err.1.gz
 missing  d /usr/share/man/man1/mysql_config.1.gz
 
 I suppose this is, albeit not ideal, tolerable?

Yeah this is fine. Your system is probably not setup to install docs and
therefore these files just didn't get installed.

 Does PHP 4 perhaps come with it's own mysql library in the source?
 Perhaps you have to pass an argument?
 
 Yes, as of PHP4 the --with-mysql is on by default. I tried specifying
 --with-mysql-dir=/usr and also shared,/usr, but to no avail.

Sorry mate I'm out of ideas... Without tracing through the configure
script to nail it down, I'm kinda stumped.

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: [PHP-INSTALL] MySQL connector installation/upgrade problems

2007-10-23 Thread Colin Guthrie
David Christopher Zentgraf wrote:
 On  23. Oct 2007, at 17:22, Colin Guthrie wrote:
 
 Do rpm -qa --nosignature | grep -i mysql and see what old libraries you
 have lying around. Specifically look for the devel libraries/packages.
 Remove the 3.x versions via RPM and make sure you've installed the
 relevant -devel package from MySQL 5.

 You can also use the MySQL 5 -shared-compat package to replace the
 shared libraries needed by other apps in Fedora, although you may have
 to do an rpm -e --nodeps to get rid of the currently installed library
 prior to installing -shared-compat due to file conflicts. I always like
 to test that this has worked tho (typically testing one of the apps in
 the packages rpm moaned about when doing a normal rpm -e (sans
 --nodeps) or by trying to rpm -e the newly installed -shared-compat just
 to make sure it is providing the correct deps at least!
 
 I did install the shared-compat package (sorry, forgot to mention),
 which littered libmysqlclient.so.10 to .so.15 around my /usr/lib, and I
 guess that PHP is using .so.10 for some reason instead of .so.15 (or
 simply libmysqlclient.so, which is symlinked to .so.15).
 Are you saying that it's save to remove the old libs or the whole
 shared-compat package and simply install the current libs instead? I was
 thinking about it, but then again, these things are there for
 compatibility, so I hoped there was a way to explicitly tell PHP to use
 the latest version while leaving the others around.

The .so file (without the .10 or .15) is just used for compile time
linking, it's not used at runtime.

No, the shared-compat is the correct one ot use here as some of the core
Centos rpms may need a mysql v3 compatible client library.


If you compile PHP and it finds v3 of mysql that means that you must
have the old development libraries for mysql 3 installed in some
capacity (I believe).

What is the output of:
rpm -qa --nosignature --nodigest | grep -i mysql

This should give some clues.

I would imagine (don't know) that PHP would use the mysql_config program
to work out which mysql is installed and get the relevent cflags and
linking options. For me this is provided by the
MySQL-devel-community-5.0.27 package from MySQL... Is this definitely
installed?

Col

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP any Mysql connection- new b

2005-01-09 Thread Sagar C Nannapaneni
You didnt mentioned where your problem is and what the error that you are
getting.
check in the line

mysql_select_db (userpass);

That you have the grant and other administrative privilages to the user and
the database
you have to operate on is mysql

mysql_select_db (mysql);

Anyhow note that PHP5 has released...i dont see any good reason why u r
still using php 3.

/sagar
- Original Message -
From: M. Sokolewicz [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Saturday, January 08, 2005 9:55 PM
Subject: [PHP] Re: PHP any Mysql connection- new b


 php 3.0???!

 man, you seriously need to think about upgrading :| PHP 3 is seriously
 outdated

 - tul
 Babu wrote:

  Hi all,
 
  I am using php 3.0 and mysql and win xp.
  i want to add users to database through php page.
 
  adduser.php
  html
  FORM METHOD=post ACTION=add.php
  Real Name: INPUT TYPE=text MAXLENGTH=70 NAME=real_name SIZE=20Br
  Username: INPUT TYPE=text MAXLENGTH=70 NAME=username SIZE=20Br
  Password: Input Type=text Maxlength=70 Name=userpass Size=10Br
 
  INPUT TYPE=submit VALUE=Add INPUT type=reset VALUE=Reset
Form/form
  /tr/td/table/tr/td/table
  /body
  /html
 
  when i enter the fileds and submit ,the action is not performed, instead
add.php file is opened.
 
  add.php
  ?
 
  $ID = uniqid(userID);
 
  $db = mysql_connect(localhost,root,halfdinner);
 
  mysql_select_db (userpass);
 
  $result = mysql_query (INSERT INTO users (id, real_name, username,
password )
  VALUES ('$ID', '$real_name', '$username', '$userpass') );
  if(!$result)
 

  echo bUser not added:/b , mysql_error();
  exit;
  }
  if($result)
 

  mysql_close($db);
  print User b$username/b added sucessfully!;
  }
  else
 

  print (Wrong Password);
  }
  ?
 
  is the problem due to mysql and php connection.i am using windows xp
with apache2.
 
  i followed the steps said by someone in the previous thread.that is
adding libmysql.dll to system32 and so on. I cannot find php_mysql.dll in
php.ini.
  can some one help
 
  Thanks
  babu
 
 
 
  -
   ALL-NEW Yahoo! Messenger - all new features - even more fun!

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP 5 MySql 4.1 issue - can't connect to mysql.sock

2004-12-20 Thread Barley
Bingo. Many thanks.


 Barley wrote:

  If I run the script from a shell prompt as root, it outputs Yes. If I
run
  as any other user, it outputs No. It also gives this error:
  Warning: mysqli_connect(): Can't connect to local MySQL server through
  socket '/var/lib/mysql/mysql.sock' (13)

 Check permissions on /var/lib/mysql. From the sockets manpage:

 NOTES
 In the Linux implementation, sockets which are visible in the filesystem
 honour the permissions of the directory they are in. Their owner, group
 and their permissions can be changed. Creation of a new socket will fail
 if the process does not have write and search (execute) permission on
 the directory the socket is created in. Connecting to the socket object
 requires read/write permission. This behavior differs from many
 BSD-derived systems which ignore permissions for Unix sockets. Portable
 programs should not rely on this feature for security.

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL date

2003-12-15 Thread John W. Holmes
Cesar Aracena wrote:

I tried what both of you told me and I found very easy to use the datetime
value under MySQL and then fetch it using strtotime() as fireball at
sizzling dot com recommended at the User Contributed Notes of php.net's
function.date.php page rather than using mktime() which can output incorrect
dates.
You can also use the MySQL function DATE_FORMAT() to format the MySQL 
timestamp to your liking. It is very similar to the PHP date() function.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: php caches mysql connections to same host

2003-06-24 Thread Robert Cummings

See the new_link parameter option for mysql_connect. It should solve
your problem. On the other hand, what you are doing is fine, I did it
for my pool since I can't use the new_link option because I'm retaining
compatibility back to PHP 4.1.2

Cheers,
Rob.


dorgon wrote:
 
 for better understanding:
 
 phpCode
$conn1 = mysql_connect(localhost, user, pwd);
mysql_select_db(database1, $conn1);
 
$conn2 = mysql_connect(localhost, user, pwd);
mysql_select_db(database2, $conn2); // select two diff. DBs
 
echo $conn1.br;
echo $conn2.br;
 /phpCode
 
 returns:
Resource id #2
Resource id #2
 
 BUT:
$conn1 = mysql_connect(127.0.0.1, user, pwd);
mysql_select_db(database1, $conn1);
$conn2 = mysql_connect(localhost, user, pwd);
mysql_select_db(database2, $conn2); // select two diff. DBs
 
 ...returns two different resource IDs (which I'd like to have).
 
 When using mysql_pconnect I'm always getting correctly different
 resource ids.
 
 /dorgon
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
.-.
| Worlds of Carnage - http://www.wocmud.org   |
:-:
| Come visit a world of myth and legend where |
| fantastical creatures come to life and the  |
| stuff of nightmares grasp for your soul.|
`-'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL bug

2003-01-08 Thread Nuno Lopes
@mysql_select_db(be); // this doesn't fail, because only the second
(UPDATE) query fails. The first query (SELECT) is done!


- Original Message -
From: Marek Kilimajer [EMAIL PROTECTED]
To: Nuno Lopes [EMAIL PROTECTED]
Cc: MySQL List [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Tuesday, January 07, 2003 5:06 PM
Subject: Re: [PHP] Re: PHP and MySQL bug


 @mysql_select_db(be); -- this failed
 do echo mysql_error(); to see what went wrong



 Nuno Lopes wrote:

 I done a echo of Mysql_error and it returned:
 'Nenhum banco de dados foi selecionado'
 
 (I have the mysql server in portuguese, but the translation is something
 like 'no db was selected')
 
 
 - Original Message -
 From: David Freeman [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Sunday, January 05, 2003 10:29 PM
 Subject: RE: [PHP] Re: PHP and MySQL bug
 
 
 
 
   @MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this
   query doesn't work
 
 Personally, I'd call it bad programming practice to do a database update
 and not check to see if it worked or not.  In this case, how are you
 determining that the query did not work?  Are you manually checking the
 database?  You don't have anything in your code to check the status of
 this query.
 
 Perhaps this might get you somewhere:
 
 $qid = @mysql_query(UPDATE d SET h = '$h' WHERE id = '$id');
 
 if (isset($qid)  mysql_affected_rows() == 1)
 {
   echo query executed;
 } else {
   echo query failed:  . mysql_error();
 }
 
 At least this way you might get some indication of where the problem is.
 
 CYA, Dave



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-08 Thread Nuno Lopes
Doesn't you have any simpler answer??


Maybe installing the new version of mysql server - I have version 3.23.49 -
should do the trick



- Original Message -
From: Larry Brown [EMAIL PROTECTED]
To: Nuno Lopes [EMAIL PROTECTED]; MySQL List [EMAIL PROTECTED]
Sent: Tuesday, January 07, 2003 4:12 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


 Since nobody is jumping in to say it is some simple configuration/setting
 personally my next step would be to shut down all services on the box that
 aren't absolutely necessary and stop everything in the registry under run
 and stop anything in the start folder of the start menu and run the same
 tests.  If no positive results I would uninstall php completely and clean
 any reference in the registry of it and then install with everything still
 shut down.  Retest, if no progress do the same with mysql.  These are
 radical and time-consuming methods, but it seems as though it is broken.
If
 you absolutely need this fixed fast you might resort to paying the
 developers to give you a solution, although it may end up being what I
just
 listed, or it could be some simple fix that we aren't aware of.

 Larry S. Brown
 Dimension Networks, Inc.
 (727) 723-8388

 -Original Message-
 From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, January 07, 2003 4:31 AM
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Subject: Re: [PHP] Re: PHP and MySQL bug

 I have the latest version of PHP (4.3.0) as module in apache 2.0.43 and
 mysql 3.23.49.
 Everything is working fine, except this.
 With pconnect the error is the same!


 - Original Message -
 From: Larry Brown [EMAIL PROTECTED]
 To: MySQL List [EMAIL PROTECTED]
 Sent: Monday, January 06, 2003 6:28 PM
 Subject: RE: [PHP] Re: PHP and MySQL bug


  This definitely sounds like a buggy installation or there may be some
  problem with the communication between the web server and the mysqld.
Is
  the db on a different machine?  Try using mysql_pconnect instead of
 connect
  just to see what result you get.  I have read some unfavorable
statements
  about using pconnect with a large number of hits so if it works you
should
  read the comments about it on php.net.  Do a search for mysql_pconnect.
 
  Larry S. Brown
  Dimension Networks, Inc.
  (727) 723-8388
 
  -Original Message-
  From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
  Sent: Monday, January 06, 2003 1:09 PM
  To: MySQL List; [EMAIL PROTECTED]
  Subject: [PHP] Re: PHP and MySQL bug
 
  The problem is if I close the connection and reopen it the query is
done,
  but if I remain with the same connection has the previous query, mysql
  returns an error.
 
 
  - Original Message -
  From: Larry Brown [EMAIL PROTECTED]
  To: MySQL List [EMAIL PROTECTED]
  Sent: Sunday, January 05, 2003 4:16 PM
  Subject: Re:PHP and MySQL bug
 
 
   Try replacing the following line...
  
   @MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this query
 doesn't
   work
  
   With...
  
   $query = UPDATE d SET h='$h' WERE id='$id';
   $queryr = mysql_query($query) or die(The sql statement does not
  execute);
  
   if(mysql_affected_rows() !== 1)
   {
  die(The sql statement is successfully run however either h did not
   change or there is an internal error.  Try executing the sql from the
   command line to make sure it otherwise works.);
   }
  
   and see which is coming back.
  
  
   Larry S. Brown
   Dimension Networks, Inc.
   (727) 723-8388




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-07 Thread Nuno Lopes
I have the latest version of PHP (4.3.0) as module in apache 2.0.43 and
mysql 3.23.49.
Everything is working fine, except this.
With pconnect the error is the same!


- Original Message -
From: Larry Brown [EMAIL PROTECTED]
To: MySQL List [EMAIL PROTECTED]
Sent: Monday, January 06, 2003 6:28 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


 This definitely sounds like a buggy installation or there may be some
 problem with the communication between the web server and the mysqld.  Is
 the db on a different machine?  Try using mysql_pconnect instead of
connect
 just to see what result you get.  I have read some unfavorable statements
 about using pconnect with a large number of hits so if it works you should
 read the comments about it on php.net.  Do a search for mysql_pconnect.

 Larry S. Brown
 Dimension Networks, Inc.
 (727) 723-8388

 -Original Message-
 From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
 Sent: Monday, January 06, 2003 1:09 PM
 To: MySQL List; [EMAIL PROTECTED]
 Subject: [PHP] Re: PHP and MySQL bug

 The problem is if I close the connection and reopen it the query is done,
 but if I remain with the same connection has the previous query, mysql
 returns an error.


 - Original Message -
 From: Larry Brown [EMAIL PROTECTED]
 To: MySQL List [EMAIL PROTECTED]
 Sent: Sunday, January 05, 2003 4:16 PM
 Subject: Re:PHP and MySQL bug


  Try replacing the following line...
 
  @MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this query
doesn't
  work
 
  With...
 
  $query = UPDATE d SET h='$h' WERE id='$id';
  $queryr = mysql_query($query) or die(The sql statement does not
 execute);
 
  if(mysql_affected_rows() !== 1)
  {
 die(The sql statement is successfully run however either h did not
  change or there is an internal error.  Try executing the sql from the
  command line to make sure it otherwise works.);
  }
 
  and see which is coming back.
 
 
  Larry S. Brown
  Dimension Networks, Inc.
  (727) 723-8388



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-07 Thread Marek Kilimajer
@mysql_select_db(be); -- this failed
do echo mysql_error(); to see what went wrong



Nuno Lopes wrote:


I done a echo of Mysql_error and it returned:
'Nenhum banco de dados foi selecionado'

(I have the mysql server in portuguese, but the translation is something
like 'no db was selected')


- Original Message -
From: David Freeman [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, January 05, 2003 10:29 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


 

 @MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this
 query doesn't work

Personally, I'd call it bad programming practice to do a database update
and not check to see if it worked or not.  In this case, how are you
determining that the query did not work?  Are you manually checking the
database?  You don't have anything in your code to check the status of
this query.

Perhaps this might get you somewhere:

$qid = @mysql_query(UPDATE d SET h = '$h' WHERE id = '$id');

if (isset($qid)  mysql_affected_rows() == 1)
{
 echo query executed;
} else {
 echo query failed:  . mysql_error();
}

At least this way you might get some indication of where the problem is.

CYA, Dave
   




 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-07 Thread Nuno Lopes
I'm using Windows 2000.


- Original Message -
From: Cleber [EMAIL PROTECTED]
To: Nuno Lopes [EMAIL PROTECTED]
Sent: Tuesday, January 07, 2003 10:23 AM
Subject: Re: [PHP] Re: PHP and MySQL bug


 Try add to /etc/hosts the name and ip of DB is located


 - Original Message -
 From: Nuno Lopes [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Tuesday, January 07, 2003 7:31 AM
 Subject: Re: [PHP] Re: PHP and MySQL bug


  I have the latest version of PHP (4.3.0) as module in apache 2.0.43 and
  mysql 3.23.49.
  Everything is working fine, except this.
  With pconnect the error is the same!
 
 
  - Original Message -
  From: Larry Brown [EMAIL PROTECTED]
  To: MySQL List [EMAIL PROTECTED]
  Sent: Monday, January 06, 2003 6:28 PM
  Subject: RE: [PHP] Re: PHP and MySQL bug
 
 
   This definitely sounds like a buggy installation or there may be some
   problem with the communication between the web server and the mysqld.
 Is
   the db on a different machine?  Try using mysql_pconnect instead of
  connect
   just to see what result you get.  I have read some unfavorable
 statements
   about using pconnect with a large number of hits so if it works you
 should
   read the comments about it on php.net.  Do a search for
mysql_pconnect.
  
   Larry S. Brown
   Dimension Networks, Inc.
   (727) 723-8388
  
   -Original Message-
   From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
   Sent: Monday, January 06, 2003 1:09 PM
   To: MySQL List; [EMAIL PROTECTED]
   Subject: [PHP] Re: PHP and MySQL bug
  
   The problem is if I close the connection and reopen it the query is
 done,
   but if I remain with the same connection has the previous query, mysql
   returns an error.
  
  
   - Original Message -
   From: Larry Brown [EMAIL PROTECTED]
   To: MySQL List [EMAIL PROTECTED]
   Sent: Sunday, January 05, 2003 4:16 PM
   Subject: Re:PHP and MySQL bug
  
  
Try replacing the following line...
   
@MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this query
  doesn't
work
   
With...
   
$query = UPDATE d SET h='$h' WERE id='$id';
$queryr = mysql_query($query) or die(The sql statement does not
   execute);
   
if(mysql_affected_rows() !== 1)
{
   die(The sql statement is successfully run however either h did
not
change or there is an internal error.  Try executing the sql from
the
command line to make sure it otherwise works.);
}
   
and see which is coming back.
   
   
Larry S. Brown
Dimension Networks, Inc.
(727) 723-8388



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-06 Thread Nuno Lopes
I done a echo of Mysql_error and it returned:
'Nenhum banco de dados foi selecionado'

(I have the mysql server in portuguese, but the translation is something
like 'no db was selected')


- Original Message -
From: David Freeman [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Sunday, January 05, 2003 10:29 PM
Subject: RE: [PHP] Re: PHP and MySQL bug



   @MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this
   query doesn't work

 Personally, I'd call it bad programming practice to do a database update
 and not check to see if it worked or not.  In this case, how are you
 determining that the query did not work?  Are you manually checking the
 database?  You don't have anything in your code to check the status of
 this query.

 Perhaps this might get you somewhere:

 $qid = @mysql_query(UPDATE d SET h = '$h' WHERE id = '$id');

 if (isset($qid)  mysql_affected_rows() == 1)
 {
   echo query executed;
 } else {
   echo query failed:  . mysql_error();
 }

 At least this way you might get some indication of where the problem is.

 CYA, Dave



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP and MySQL bug

2003-01-05 Thread David Freeman

  @MYSQL_QUERY(UPDATE d SET h='$h' WHERE id='$id'); // this
  query doesn't work

Personally, I'd call it bad programming practice to do a database update
and not check to see if it worked or not.  In this case, how are you
determining that the query did not work?  Are you manually checking the
database?  You don't have anything in your code to check the status of
this query.

Perhaps this might get you somewhere:

$qid = @mysql_query(UPDATE d SET h = '$h' WHERE id = '$id');

if (isset($qid)  mysql_affected_rows() == 1)
{
  echo query executed;
} else {
  echo query failed:  . mysql_error();
}

At least this way you might get some indication of where the problem is.

CYA, Dave




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-04 Thread Michael J. Pawlowsky

Personally I say get yourself a good simple dbconnect class and make life easy.
Also if you ever change users, database name etc, you onlu have one place to replace 
it in your code.

I wrote mine based on http://www.vtwebwizard.com/tutorials/mysql/

Take a look at it.  Nice and simple.


Mike



*** REPLY SEPARATOR  ***

On 04/01/2003 at 1:09 PM OrangeHairedBoy wrote:

You really should be using a $link variable...it's good habit:

$link = mysql_connect(...);
mysql_select_db( mydb , $link);
$query = mysql_query( select... , $link );
$result = mysql_fetch_array($query);




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-04 Thread Michael J. Pawlowsky

Personally I think the problem lies somewhere between the chair and the keyboard

(Sorry, couldn't resist)  :-)



*** REPLY SEPARATOR  ***

On 04/01/2003 at 4:58 PM Stefan Hinz, iConnect (Berlin) wrote:

It doesn't work because of the /* Some code including ... */ part ;-)





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP and mySQL

2002-05-13 Thread John Holmes

Why can't you use one query?

UPDATE Book2 SET stock = stock - $quantity WHERE stock = $quantity AND
booktitle = '$booktitle'

---John Holmes...

 -Original Message-
 From: Matthew Ward [mailto:[EMAIL PROTECTED]]
 Sent: Monday, May 13, 2002 11:52 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: PHP and mySQL
 
 I presume that quantity is the number of books that the person has
 ordered, and therefore it needs to be a variable (ie with a $ infront
of
 it)
 and its also best to do the calculation outside of the SQL statement
just
 to
 be sure it works, eg:
 
 if ($submit){
if(isset($booktitle)  isset($quantity)){
   $retrievestock = mysql_query(SELECT stock FROM Book2 WHERE
 booktitle
 = '$booktitle');
   while($getstock = mysql_fetch_array($retrievestock)) {
  $stockamount = $getstock[stock];
   }
 
   $newamount = $stockamount - $quantity;
 
   $sql = mysql_query(UPDATE Book2 SET stock = '$newamount' WHERE
 booktitle= '$booktitle');
   if(! $sql) { print(Could not update stock amount.);
 } elseif(! $submit) {
print(Your order has not been placed.p);
 }
 
 
 City Colleges Of Chicago - Mannheim [EMAIL PROTECTED] wrote in
 message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  I am a student working on a practicum problem. I have a mySQL
database
 that
  contains the books, their title, and how many are in stock.  When a
 person
  orders one of the books, I want the stock to be adjusted by how
many,
  quantity, that they chose when the submit button is clicked.  The
 scripts
  are written in PHP.
  Here is part of my code:
  PThe book you are ordering:
 
  ?
  echo  $booktitle ;
   ?
 
  PAdditional Message:br
   textarea name=message cols=30 rows=3/textarea
  /p
  INPUT type=submit value=Send your order.
  input type=hidden name=booktitle value=? print $booktitle; ?
  /FORM
 
  ?php
   $user = adminer;
   $pass = hoosiers;
   $db = Book Store1;
   $local = jolinux;
   $link = mysql_connect( $local, $user, $pass   );
   if (! $link )
 die ( Couldn't open the database );
   mysql_select_db( $db, $link )
   or die ( Couldn't open the $db: .mysql_error() );
 
   if ($submit){
   if( $booktitle, 'quantity' ){
  $sql = UPDATE Book2 SET stock ='$stock-quantity' WHERE
 booktitle=$booktitle
  AND quantity=quantity;
   }
  // $result = mysql_query($mysql);
   }else if(!$submit){
echo Your order has not been placed.p;
   }
   ?
  /BODY
  /HTML
 
 
 
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP with MySQL

2002-05-03 Thread .ben

Just out of interest, what's the standard/best/triedtested method for
handling errors in relation to connecting to DB's?  i.e. how to check that
the connection was a success, and if not then display why.

any pointers appreciated.

 .b

 -Original Message-
 From: Mike Eheler [mailto:[EMAIL PROTECTED]]
 Sent: 03 May 2002 02:28
 To: [EMAIL PROTECTED]
 Subject: [PHP] Re: PHP with MySQL


 Typically it's done like:

 $db = mysql_connect('localhost','username','password');

 The MySQL database detects what host you're connecting from, and appends
 that to your username. I'm not sure if it's possible to specify an
 alternate host.

 So if both PHP and MySQL are on the same machine, and you connect to the
 MySQL server as 'username', MySQL will see you as 'username@localhost'.

 Mike


 Paras Mukadam wrote:
  Hi Gurus,
  one MySQL - PHP query : while granting permissions to particular user in
  MySQL, the administrator has to give username@machine_address
 !! Then how
  can we connect to MySQL through PHP only by passing username
 as one of the
  arguments to mysql_connect() ?
 
  Thanks.
  Paras.


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP with MySQL

2002-05-03 Thread .ben

John, presumably I can leave the error reporting on - but pipe it into a
file if i wanted, rather than displaying on screen, and then redirect the
user to another page?

Not asking for code sample here, just whether I can do it or not :)

/me goes to look up mysql_error()

Cheers,

 .b

 -Original Message-
 From: Jon Haworth [mailto:[EMAIL PROTECTED]]
 Sent: 03 May 2002 11:34
 To: '[EMAIL PROTECTED]'; PHP
 Subject: RE: [PHP] Re: PHP with MySQL


 Hi .ben,

  Just out of interest, what's the standard/best/tried
  tested method for handling errors in relation to
  connecting to DB's?  i.e. how to check that the
  connection was a success, and if not then display why.

 Something like...

 $dbh = mysql_connect (foo, bar, baz)
   or die (mysql_error ());

 has always worked well for me. When it comes to queries I
 generally tack the
 SQL on the end of the error, like this:

 $q = mysql_query ($sql, $dbh)
   or die (mysql_error (). brb. $sql. /b);

 Obviously it's a good idea to turn this error reporting off on a
 production
 site, otherwise you risk exposing details of your database structure.

 HTH
 Jon


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP with MySQL

2002-05-03 Thread Jon Haworth

Hi Ben,

 John, presumably I can leave the error reporting on - 
 but pipe it into a file if i wanted, rather than 
 displaying on screen, and then redirect the user to 
 another page?

Of course you can - I generally have my pages send me email when they throw
an error, but that's because I'm really lazy and I can't be bothered to go
and check log files all the time g

It's just not a stunning idea to display an error messages that give away
out any information you could hold back - one of the starting points for an
attacker is to try and mess up your query strings, and if you're merrily
telling them exactly what the problem is, you're helping them out :-)

Cheers
Jon

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP with MySQL

2002-05-03 Thread .ben

Oh, i agree entirely.

Ok, i'll look into the logging/mailing solution - something i've been doing
in ASP for years but am new to in PHP.

Cheers,

 .b

 -Original Message-
 From: Jon Haworth [mailto:[EMAIL PROTECTED]]
 Sent: 03 May 2002 11:57
 To: '[EMAIL PROTECTED]'; PHP
 Subject: RE: [PHP] Re: PHP with MySQL


 Hi Ben,

  John, presumably I can leave the error reporting on -
  but pipe it into a file if i wanted, rather than
  displaying on screen, and then redirect the user to
  another page?

 Of course you can - I generally have my pages send me email when
 they throw
 an error, but that's because I'm really lazy and I can't be bothered to go
 and check log files all the time g

 It's just not a stunning idea to display an error messages that give away
 out any information you could hold back - one of the starting
 points for an
 attacker is to try and mess up your query strings, and if you're merrily
 telling them exactly what the problem is, you're helping them out :-)

 Cheers
 Jon


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP with MySQL

2002-05-03 Thread John Holmes

There's a whole section in the manual on it. There is a log_error() or
errorlog() function that'll write your errors to a file of your
choosing. 

---John Holmes...

 -Original Message-
 From: .ben [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 03, 2002 4:04 AM
 To: PHP
 Subject: RE: [PHP] Re: PHP with MySQL
 
 Oh, i agree entirely.
 
 Ok, i'll look into the logging/mailing solution - something i've been
 doing
 in ASP for years but am new to in PHP.
 
 Cheers,
 
  .b
 
  -Original Message-
  From: Jon Haworth [mailto:[EMAIL PROTECTED]]
  Sent: 03 May 2002 11:57
  To: '[EMAIL PROTECTED]'; PHP
  Subject: RE: [PHP] Re: PHP with MySQL
 
 
  Hi Ben,
 
   John, presumably I can leave the error reporting on -
   but pipe it into a file if i wanted, rather than
   displaying on screen, and then redirect the user to
   another page?
 
  Of course you can - I generally have my pages send me email when
  they throw
  an error, but that's because I'm really lazy and I can't be bothered
to
 go
  and check log files all the time g
 
  It's just not a stunning idea to display an error messages that give
 away
  out any information you could hold back - one of the starting
  points for an
  attacker is to try and mess up your query strings, and if you're
merrily
  telling them exactly what the problem is, you're helping them out
:-)
 
  Cheers
  Jon
 
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP with MySQL

2002-05-03 Thread .ben

Thanks John.

 -Original Message-
 From: John Holmes [mailto:[EMAIL PROTECTED]]
 Sent: 03 May 2002 16:29
 To: [EMAIL PROTECTED]; 'PHP'
 Subject: RE: [PHP] Re: PHP with MySQL
 
 
 There's a whole section in the manual on it. There is a log_error() or
 errorlog() function that'll write your errors to a file of your
 choosing. 
 
 ---John Holmes...
 
  -Original Message-
  From: .ben [mailto:[EMAIL PROTECTED]]
  Sent: Friday, May 03, 2002 4:04 AM
  To: PHP
  Subject: RE: [PHP] Re: PHP with MySQL
  
  Oh, i agree entirely.
  
  Ok, i'll look into the logging/mailing solution - something i've been
  doing
  in ASP for years but am new to in PHP.
  
  Cheers,
  
   .b
  
   -Original Message-
   From: Jon Haworth [mailto:[EMAIL PROTECTED]]
   Sent: 03 May 2002 11:57
   To: '[EMAIL PROTECTED]'; PHP
   Subject: RE: [PHP] Re: PHP with MySQL
  
  
   Hi Ben,
  
John, presumably I can leave the error reporting on -
but pipe it into a file if i wanted, rather than
displaying on screen, and then redirect the user to
another page?
  
   Of course you can - I generally have my pages send me email when
   they throw
   an error, but that's because I'm really lazy and I can't be bothered
 to
  go
   and check log files all the time g
  
   It's just not a stunning idea to display an error messages that give
  away
   out any information you could hold back - one of the starting
   points for an
   attacker is to try and mess up your query strings, and if you're
 merrily
   telling them exactly what the problem is, you're helping them out
 :-)
  
   Cheers
   Jon
  
  
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP and mySQL

2002-03-05 Thread Dan Vande More

Max,
PHP.net says:

Calls to mysql_result() should not be mixed with calls to other functions
that deal with the result set. 

I would use mysql_fetch_array which they say is MUCH faster, example of how
you could use it:

?php
mysql_connect($host, $user, $password);
mysql_select_db(database);
$sqlinfo = SELECT username, COUNT(username) as count FROM usertable WHERE 
username='me' GROUP BY username;

$number_of_rows=mysql_num_rows($sqlinfo)
if($number_of_rows != '0')
{
while ($row = mysql_fetch_array($sqlinfo)) 
{
 echo count: .$row[count].br\n;
 echo username: .$row[username].br\n;
}
}
mysql_free_result($result);
?


-Original Message-
From: David Robley [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, March 05, 2002 8:29 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: PHP and mySQL

In article 180f01c1c403$2ac62820$[EMAIL PROTECTED], 
[EMAIL PROTECTED] says...
 I have a little problem when trying to count the number of results
returned
 in a mysql query. I was using mysql_num_rows() to do it with no problems,
 but this isn't as quick as using mySQL's COUNT(*), or so I have been told
so
 I swtiched. Here's a snipit of the code...
 
 $sqlinfo = SELECT username, COUNT(username) as count FROM usertable WHERE
 username='me' GROUP BY username;
 $sqlresult = mysql_query($sqlinfo)
   or die(mysql_error());
 
 $count = mysql_result($sqlresult,0,count);
 
 if ($count = 0) {
   FAILED
 } else {
   while ($row = mysql_fetch_array($sqlresult)) {
 $username = $row['username'];
   }
 }
 
 The count value is set correctly but:  when the while() loop is
 executed...no values are set (there are a lot more, but I shortened it for
 spaces sake). So, $username is null. If I remove the $count line, it
 worksany suggestions?
 
 Max

Assuming that your username is unique, I would expect that you would only 
get one row returned from that query? In which case much of your SQL is 
redundant.

Anyhow, your $count line reads the first row of the result, then sets the 
pointer to the next row in the result set - if this is empty (ie only one 
row retrieved) then you will get a null result for your while loop as 
there are no more results to display. Try using mysql_data_seek to return 
the pointer to row 0 before your while loop.


-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php