php-general Digest 13 Sep 2011 19:36:47 -0000 Issue 7476
Topics (messages 314780 through 314811):
Re: Stop PHP execution on client connection closed
314780 by: vikash.iitb.gmail.com
314781 by: Marco Lanzotti
314788 by: Eric Butera
314789 by: yeer tai
314798 by: Ian
314799 by: Marco Lanzotti
314800 by: Jim Lucas
314807 by: Alex Nikitin
314809 by: Jim Lucas
314810 by: Alex Nikitin
PHP FPM and OCI8 crashes
314782 by: linuxsupport
PHP FPM and OCI crashes
314783 by: linuxsupport
314784 by: Negin Nickparsa
314785 by: linuxsupport
314786 by: Negin Nickparsa
314787 by: linuxsupport
314795 by: linuxsupport
314808 by: Alex Nikitin
Querying a database for 50 users' information: 50 queries or a WHERE array?
314790 by: Dotan Cohen
314791 by: Ashley Sheridan
314792 by: muad shibani
314793 by: Steve Staples
314794 by: yeer tai
314796 by: Ashley Sheridan
314797 by: Eric Butera
314801 by: David Harkness
314802 by: Steve Staples
314803 by: Marc Guay
314804 by: Alex Nikitin
314811 by: Dotan Cohen
htmlentities
314805 by: Ron Piggott
314806 by: Marc Guay
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 ---
On 13 September 2011 13:05, Marco Lanzotti <ma...@lanzotti.com> wrote:
> Il 12/09/2011 21:32, Al ha scritto:
> > See http://us2.php.net/manual/en/function.connection-aborted.php
>
> As I wrote, PHP doesn't detect that client aborted connection until it
> send some data.
> During query the script doesn't send any data to client, so it doesn't
> detect client aborted connenction.
> I know this function, but it's useless to solve my problem...
>
You can use ob_start() to start output buffering and ob_end_flush() to send
some data in the middle of script - that way your php script will send
some data to the client earlier than finishing execution and hence detect
the aborted connection.
>
> Bye,
> Marco
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Il 13/09/2011 09:39, vikash.i...@gmail.com ha scritto:
>
> You can use ob_start() to start output buffering and ob_end_flush() to send
> some data in the middle of script - that way your php script will send
> some data to the client earlier than finishing execution and hence detect
> the aborted connection.
The question is: how can I send data to client until I'm waiting for
query execution? PHP thread support is not available in Apache enviroment.
Bye,
Marco
--- End Message ---
--- Begin Message ---
On Tue, Sep 13, 2011 at 4:01 AM, Marco Lanzotti <ma...@lanzotti.com> wrote:
> Il 13/09/2011 09:39, vikash.i...@gmail.com ha scritto:
>>
>> You can use ob_start() to start output buffering and ob_end_flush() to send
>> some data in the middle of script - that way your php script will send
>> some data to the client earlier than finishing execution and hence detect
>> the aborted connection.
>
> The question is: how can I send data to client until I'm waiting for
> query execution? PHP thread support is not available in Apache enviroment.
>
> Bye,
> Marco
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Flush all buffers you have. Sometimes you have to do nasty hacks like
send a certain number of characters. Execution will still continue
along after your buffers are send if it is still blocking for a query.
You might have better luck if you search for 'comet' or 'long polling.'
--- End Message ---
--- Begin Message ---
You can use ajax.
> Date: Tue, 13 Sep 2011 09:22:54 -0400
> From: eric.but...@gmail.com
> To: ma...@lanzotti.com
> CC: php-gene...@lists.php.net
> Subject: Re: [PHP] Re: Stop PHP execution on client connection closed
>
> On Tue, Sep 13, 2011 at 4:01 AM, Marco Lanzotti <ma...@lanzotti.com> wrote:
> > Il 13/09/2011 09:39, vikash.i...@gmail.com ha scritto:
> >>
> >> You can use ob_start() to start output buffering and ob_end_flush() to send
> >> some data in the middle of script - that way your php script will send
> >> some data to the client earlier than finishing execution and hence detect
> >> the aborted connection.
> >
> > The question is: how can I send data to client until I'm waiting for
> > query execution? PHP thread support is not available in Apache enviroment.
> >
> > Bye,
> > Marco
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> Flush all buffers you have. Sometimes you have to do nasty hacks like
> send a certain number of characters. Execution will still continue
> along after your buffers are send if it is still blocking for a query.
>
> You might have better luck if you search for 'comet' or 'long polling.'
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
On 13/09/2011 09:01, Marco Lanzotti wrote:
> Il 13/09/2011 09:39, vikash.i...@gmail.com ha scritto:
>>
>> You can use ob_start() to start output buffering and ob_end_flush() to send
>> some data in the middle of script - that way your php script will send
>> some data to the client earlier than finishing execution and hence detect
>> the aborted connection.
>
> The question is: how can I send data to client until I'm waiting for
> query execution? PHP thread support is not available in Apache enviroment.
>
> Bye,
> Marco
>
Hi Marco,
You may have to think of this problem a different way.
How about about creating a job queuing system to handle the long running
database queries. You will have to break it down into steps:
User initiatives Query via AJAX call.
System receives query and adds it to queue, return status of 'Added to
queue'
System daemon monitors job queue and runs / records status / stores
results of jobs.
Background process on web page monitors job status via AJAX calls and
alerts user when complete.
On linux systems, The pear module 'System Daemon' is very good for job
queues and easy to install:
[http://pear.php.net/package/System_Daemon]
Hope this helps.
Ian
--
--- End Message ---
--- Begin Message ---
Il 13/09/2011 15:22, Eric Butera ha scritto:
> Flush all buffers you have. Sometimes you have to do nasty hacks like
> send a certain number of characters.
I'm looking for a way to send some characters during query execution.
> You might have better luck if you search for 'comet' or 'long polling.'
Long polling requires script interaction. How can I interact while I'm
waiting for query to be executed?
Bye,
Marco
--- End Message ---
--- Begin Message ---
On 9/12/2011 7:40 AM, Marco Lanzotti wrote:
> Hi all, I'm new in the list and I already have a question for you.
> I'm running an heavy query on my DB in a PHP script called by AJAX.
> Because client often abort AJAX connection to ask a new query, I need to
> stop query because DB will be too loaded.
> When AJAX connection is aborted, PHP script doesn't stop until it send
> some output to client, so I need to wait query execution to know client
> aborted connection.
> How can I abort query (or script) when AJAX connection is aborted?
>
> Thank you,
> Marco
>
>
You cannot stop a DB query.
What this means is PHP will not be able to do anything else until the db has
finished its step and handed data back to the processing script. At that point,
you can check to see if the connection is still active and take appropriate
action.
Jim Lucas
--- End Message ---
--- Begin Message ---
On Tue, Sep 13, 2011 at 11:44 AM, Jim Lucas <li...@cmsws.com> wrote:
> On 9/12/2011 7:40 AM, Marco Lanzotti wrote:
> > Hi all, I'm new in the list and I already have a question for you.
> > I'm running an heavy query on my DB in a PHP script called by AJAX.
> > Because client often abort AJAX connection to ask a new query, I need to
> > stop query because DB will be too loaded.
> > When AJAX connection is aborted, PHP script doesn't stop until it send
> > some output to client, so I need to wait query execution to know client
> > aborted connection.
> > How can I abort query (or script) when AJAX connection is aborted?
> >
> > Thank you,
> > Marco
> >
> >
>
> You cannot stop a DB query.
>
> What this means is PHP will not be able to do anything else until the db
> has
> finished its step and handed data back to the processing script. At that
> point,
> you can check to see if the connection is still active and take appropriate
> action.
>
> Jim Lucas
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Correction on Marco's post. You can absolutely stop a mysql query, it is
done with a large amount of success at Facebook for example, where they have
very strict query execution rules, e.g. if your query takes too long to run,
it is killed. However unless you are dealing with enormous data sets, or
very very slow mysql server, this is not worth the tremendous amount of
trouble you would have to go through. And if you are dealing with enormous
data sets or slow servers, it would be far more beneficial to address those
issue then to implement the query killing thing.
MySQL commands in question are:
SHOW PROCESSLIST;
KILL [thread];
You can also hook into if you really wanted to with some C through the API,
but again, it is far more trouble than most people need, and problems often
lay else-where (for example inefficient query or bad database design or
matching on non-indexed cols etc...) A query that ties together 3 tables and
pulls 80-90k rows @10 columns shouldn't take more than 0.25 sec to execute,
maybe a second for the whole operation from connect to result, if your mysql
server is one hop away (i.e. they are on the same switch), the tcp hand
shake can take up to 100ms, plus you need to get the process list, traverse
it for your query, and send a kill command. I'm going to guess that the kill
process will take longer to connect, list, parse and kill, then it will take
the query to finish and return data...
What is your data set like, what are you trying to accomplish by this other
than complicating your code?
Also yes, AJAX is your friend (avoid pulling large or any data sets if you
can), as well as some query and database optimization, and caching ;)
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
--- End Message ---
--- Begin Message ---
On 9/13/2011 11:58 AM, Alex Nikitin wrote:
> On Tue, Sep 13, 2011 at 11:44 AM, Jim Lucas <li...@cmsws.com> wrote:
>
>> On 9/12/2011 7:40 AM, Marco Lanzotti wrote:
>>> Hi all, I'm new in the list and I already have a question for you.
>>> I'm running an heavy query on my DB in a PHP script called by AJAX.
>>> Because client often abort AJAX connection to ask a new query, I need to
>>> stop query because DB will be too loaded.
>>> When AJAX connection is aborted, PHP script doesn't stop until it send
>>> some output to client, so I need to wait query execution to know client
>>> aborted connection.
>>> How can I abort query (or script) when AJAX connection is aborted?
>>>
>>> Thank you,
>>> Marco
>>>
>>>
>>
>> You cannot stop a DB query.
>>
>> What this means is PHP will not be able to do anything else until the db
>> has
>> finished its step and handed data back to the processing script. At that
>> point,
>> you can check to see if the connection is still active and take appropriate
>> action.
>>
>> Jim Lucas
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> Correction on Marco's post. You can absolutely stop a mysql query, it is
> done with a large amount of success at Facebook for example, where they have
> very strict query execution rules, e.g. if your query takes too long to run,
> it is killed. However unless you are dealing with enormous data sets, or
> very very slow mysql server, this is not worth the tremendous amount of
> trouble you would have to go through. And if you are dealing with enormous
> data sets or slow servers, it would be far more beneficial to address those
> issue then to implement the query killing thing.
>
> MySQL commands in question are:
> SHOW PROCESSLIST;
> KILL [thread];
>
> You can also hook into if you really wanted to with some C through the API,
> but again, it is far more trouble than most people need, and problems often
> lay else-where (for example inefficient query or bad database design or
> matching on non-indexed cols etc...) A query that ties together 3 tables and
> pulls 80-90k rows @10 columns shouldn't take more than 0.25 sec to execute,
> maybe a second for the whole operation from connect to result, if your mysql
> server is one hop away (i.e. they are on the same switch), the tcp hand
> shake can take up to 100ms, plus you need to get the process list, traverse
> it for your query, and send a kill command. I'm going to guess that the kill
> process will take longer to connect, list, parse and kill, then it will take
> the query to finish and return data...
>
> What is your data set like, what are you trying to accomplish by this other
> than complicating your code?
>
> Also yes, AJAX is your friend (avoid pulling large or any data sets if you
> can), as well as some query and database optimization, and caching ;)
>
>
>
> --
> The trouble with programmers is that you can never tell what a programmer is
> doing until it’s too late. ~Seymour Cray
>
My statement still stands.
>> What this means is PHP will not be able to do anything else until the db
>> has finished its step and handed data back to the processing script.
--- End Message ---
--- Begin Message ---
Absolutely, it was only a minor correction of a sub-point.
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
On Tue, Sep 13, 2011 at 3:20 PM, Jim Lucas <li...@cmsws.com> wrote:
> On 9/13/2011 11:58 AM, Alex Nikitin wrote:
> > On Tue, Sep 13, 2011 at 11:44 AM, Jim Lucas <li...@cmsws.com> wrote:
> >
> >> On 9/12/2011 7:40 AM, Marco Lanzotti wrote:
> >>> Hi all, I'm new in the list and I already have a question for you.
> >>> I'm running an heavy query on my DB in a PHP script called by AJAX.
> >>> Because client often abort AJAX connection to ask a new query, I need
> to
> >>> stop query because DB will be too loaded.
> >>> When AJAX connection is aborted, PHP script doesn't stop until it send
> >>> some output to client, so I need to wait query execution to know client
> >>> aborted connection.
> >>> How can I abort query (or script) when AJAX connection is aborted?
> >>>
> >>> Thank you,
> >>> Marco
> >>>
> >>>
> >>
> >> You cannot stop a DB query.
> >>
> >> What this means is PHP will not be able to do anything else until the db
> >> has
> >> finished its step and handed data back to the processing script. At
> that
> >> point,
> >> you can check to see if the connection is still active and take
> appropriate
> >> action.
> >>
> >> Jim Lucas
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
> >>
> > Correction on Marco's post. You can absolutely stop a mysql query, it is
> > done with a large amount of success at Facebook for example, where they
> have
> > very strict query execution rules, e.g. if your query takes too long to
> run,
> > it is killed. However unless you are dealing with enormous data sets, or
> > very very slow mysql server, this is not worth the tremendous amount of
> > trouble you would have to go through. And if you are dealing with
> enormous
> > data sets or slow servers, it would be far more beneficial to address
> those
> > issue then to implement the query killing thing.
> >
> > MySQL commands in question are:
> > SHOW PROCESSLIST;
> > KILL [thread];
> >
> > You can also hook into if you really wanted to with some C through the
> API,
> > but again, it is far more trouble than most people need, and problems
> often
> > lay else-where (for example inefficient query or bad database design or
> > matching on non-indexed cols etc...) A query that ties together 3 tables
> and
> > pulls 80-90k rows @10 columns shouldn't take more than 0.25 sec to
> execute,
> > maybe a second for the whole operation from connect to result, if your
> mysql
> > server is one hop away (i.e. they are on the same switch), the tcp hand
> > shake can take up to 100ms, plus you need to get the process list,
> traverse
> > it for your query, and send a kill command. I'm going to guess that the
> kill
> > process will take longer to connect, list, parse and kill, then it will
> take
> > the query to finish and return data...
> >
> > What is your data set like, what are you trying to accomplish by this
> other
> > than complicating your code?
> >
> > Also yes, AJAX is your friend (avoid pulling large or any data sets if
> you
> > can), as well as some query and database optimization, and caching ;)
> >
> >
> >
> > --
> > The trouble with programmers is that you can never tell what a programmer
> is
> > doing until it’s too late. ~Seymour Cray
> >
>
> My statement still stands.
>
> >> What this means is PHP will not be able to do anything else until the db
> >> has finished its step and handed data back to the processing script.
>
>
--- End Message ---
--- Begin Message ---
Hi,
Recently, I decided to use PHP FPM, installation went well, I configured it
with Nginx.
I can run php script without any issue.
But when I used a script to connect to Oracle database using oci module, I
got a blank page.
Below is the code I am using in script.
<?php
$c = oci_connect("mydb", "password", 'DEV');
if(!c)
{
$e = oci_error();
print htmlentities($e['message']);
exit;
}
else
{
echo '<br />Connection is OK';
}
?>
If I run this script from command line it works well.
-------
/usr/local/php/bin/php db_test.php
Connection is ok
------
But when I run it from Web it does not return any thing, I got following
error in FPM log, nothing else.
WARNING: [pool www] child 15712 exited on signal 11 (SIGSEGV) after
3986.160925 seconds from start
It is getting segfault.
Anyone can suggest what could be possible reason.
PHP veriosn 5.3.8
--- End Message ---
--- Begin Message ---
Hi,
Recently, I decided to use PHP FPM, installation went well, I configured it
with Nginx.
I can run php script without any issue.
But when I used a script to connect to Oracle database using oci module, I
got a blank page.
Below is the code I am using in script.
<?php
$c = oci_connect("mydb", "password", 'DEV');
if(!c)
{
$e = oci_error();
print htmlentities($e['message']);
exit;
}
else
{
echo '<br />Connection is OK';
}
?>
If I run this script from command line it works well.
-------
/usr/local/php/bin/php db_test.php
Connection is ok
------
But when I run it from Web it does not return any thing, I got following
error in FPM log, nothing else.
WARNING: [pool www] child 15712 exited on signal 11 (SIGSEGV) after
3986.160925 seconds from start
It is getting segfault.
Anyone can suggest what could be possible reason.
PHP veriosn 5.3.8
--- End Message ---
--- Begin Message ---
is your oci module enabled in php.ini?
I mean something like this?
extension=oci8.so
--- End Message ---
--- Begin Message ---
Yes, it is enabled, I checked through phpinfo()
On Tue, Sep 13, 2011 at 2:54 PM, Negin Nickparsa <nickpa...@gmail.com>wrote:
> is your oci module enabled in php.ini?
> I mean something like this?
> extension=oci8.so
>
--- End Message ---
--- Begin Message ---
use gdb
--- End Message ---
--- Begin Message ---
Could you please tell me how to use GDB here?
On Tue, Sep 13, 2011 at 4:07 PM, Negin Nickparsa <nickpa...@gmail.com>wrote:
> use gdb
>
--- End Message ---
--- Begin Message ---
I enabled debug in log and found this in the log file
[13-Sep-2011 17:03:19.966801] DEBUG: pid 16974, fpm_got_signal(), line 76:
received SIGCHLD
[13-Sep-2011 17:03:19.966832] WARNING: pid 16974, fpm_children_bury(), line
252: [pool www] child 16992 exited on signal 11 (SIGSEGV) after 58.213448
seconds from start
[13-Sep-2011 17:03:19.967678] NOTICE: pid 16974, fpm_children_make(), line
404: [pool www] child 16996 started
Anyone can suggest me to fix this.
On Tue, Sep 13, 2011 at 5:41 PM, linuxsupport <lin.supp...@gmail.com> wrote:
> Could you please tell me how to use GDB here?
>
> On Tue, Sep 13, 2011 at 4:07 PM, Negin Nickparsa <nickpa...@gmail.com>wrote:
>
>> use gdb
>>
>
>
--- End Message ---
--- Begin Message ---
On Tue, Sep 13, 2011 at 10:40 AM, linuxsupport <lin.supp...@gmail.com>wrote:
> I enabled debug in log and found this in the log file
>
> [13-Sep-2011 17:03:19.966801] DEBUG: pid 16974, fpm_got_signal(), line 76:
> received SIGCHLD
> [13-Sep-2011 17:03:19.966832] WARNING: pid 16974, fpm_children_bury(), line
> 252: [pool www] child 16992 exited on signal 11 (SIGSEGV) after 58.213448
> seconds from start
> [13-Sep-2011 17:03:19.967678] NOTICE: pid 16974, fpm_children_make(), line
> 404: [pool www] child 16996 started
>
>
> Anyone can suggest me to fix this.
>
> On Tue, Sep 13, 2011 at 5:41 PM, linuxsupport <lin.supp...@gmail.com>
> wrote:
>
> > Could you please tell me how to use GDB here?
> >
> > On Tue, Sep 13, 2011 at 4:07 PM, Negin Nickparsa <nickpa...@gmail.com
> >wrote:
> >
> >> use gdb
> >>
> >
> >
>
Regarding gdb backtrace:
https://bugs.php.net/bugs-generating-backtrace.php
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
--- End Message ---
--- Begin Message ---
I have a MySQL database table with about 10,000 rows. If I want to
query for 50 specific users (so no LIMIT ORDER BY) then I seem to have
these choices:
1) SELECT * FROM table
This will pull in all 10,000 rows, not nice!
2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
userID=".$u); }
This will lead to 50 queries, again not nice! (maybe worse)
3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
This makes a huge SQL query. However, this is the method that I'm using now.
Is there some sort of array that can be passed in the WHERE clause,
containing all the userID's that I am interested in?
Thanks!
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
--- End Message ---
--- Begin Message ---
Dotan Cohen <dotanco...@gmail.com> wrote:
>I have a MySQL database table with about 10,000 rows. If I want to
>query for 50 specific users (so no LIMIT ORDER BY) then I seem to have
>these choices:
>
>1) SELECT * FROM table
>This will pull in all 10,000 rows, not nice!
>
>2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
>userID=".$u); }
>This will lead to 50 queries, again not nice! (maybe worse)
>
>3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
>This makes a huge SQL query. However, this is the method that I'm using
>now.
>
>Is there some sort of array that can be passed in the WHERE clause,
>containing all the userID's that I am interested in?
>
>Thanks!
>
>--
>Dotan Cohen
>
>http://gibberish.co.il
>http://what-is-what.com
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
Much smaller than what you proposed in #3, and easier to make if your user is
list is already an array.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--- End Message ---
--- Begin Message ---
Yes there is but all the IDs in one string like this
$ids = $id1.', '.$id2.', ' ;
note : remove the last comma from the string
the make the query like this:
mysql_query("SELECT * FROM table WHERE
userID= in($ids ) }
On Tue, Sep 13, 2011 at 7:24 AM, Dotan Cohen <dotanco...@gmail.com> wrote:
> I have a MySQL database table with about 10,000 rows. If I want to
> query for 50 specific users (so no LIMIT ORDER BY) then I seem to have
> these choices:
>
> 1) SELECT * FROM table
> This will pull in all 10,000 rows, not nice!
>
> 2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
> userID=".$u); }
> This will lead to 50 queries, again not nice! (maybe worse)
>
> 3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
> This makes a huge SQL query. However, this is the method that I'm using
> now.
>
> Is there some sort of array that can be passed in the WHERE clause,
> containing all the userID's that I am interested in?
>
> Thanks!
>
> --
> Dotan Cohen
>
> http://gibberish.co.il
> http://what-is-what.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Tue, 2011-09-13 at 17:24 +0300, Dotan Cohen wrote:
> I have a MySQL database table with about 10,000 rows. If I want to
> query for 50 specific users (so no LIMIT ORDER BY) then I seem to have
> these choices:
>
> 1) SELECT * FROM table
> This will pull in all 10,000 rows, not nice!
>
> 2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
> userID=".$u); }
> This will lead to 50 queries, again not nice! (maybe worse)
>
> 3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
> This makes a huge SQL query. However, this is the method that I'm using now.
>
> Is there some sort of array that can be passed in the WHERE clause,
> containing all the userID's that I am interested in?
>
> Thanks!
>
> --
> Dotan Cohen
>
> http://gibberish.co.il
> http://what-is-what.com
>
what criteria are you using to get the "stats" for these 50 users?
also, wouldn't this be much better suited for the mysql mailing list?
if you know all the userids, then you could just do it as:
$sql = "SELECT * FROM table WHERE userid IN (". implode(', ',
$usersids) .")";
not very elegant, and I am not sure that the IN is any better than doing
50 mysql calls, but this is only 1 call, and gets you the data.
Are you querying the database to get the id's in the frist place? if
so, you could look at doing an inner join on the 2 tables.
--
Steve Staples
Web Application Developer
--- End Message ---
--- Begin Message ---
select * from table where userID in(1,2,3,etc)
> From: a...@ashleysheridan.co.uk
> Date: Tue, 13 Sep 2011 15:29:26 +0100
> To: dotanco...@gmail.com; php-gene...@lists.php.net
> Subject: Re: [PHP] Querying a database for 50 users' information: 50 queries
> or a WHERE array?
>
>
>
> Dotan Cohen <dotanco...@gmail.com> wrote:
>
> >I have a MySQL database table with about 10,000 rows. If I want to
> >query for 50 specific users (so no LIMIT ORDER BY) then I seem to have
> >these choices:
> >
> >1) SELECT * FROM table
> >This will pull in all 10,000 rows, not nice!
> >
> >2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
> >userID=".$u); }
> >This will lead to 50 queries, again not nice! (maybe worse)
> >
> >3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
> >This makes a huge SQL query. However, this is the method that I'm using
> >now.
> >
> >Is there some sort of array that can be passed in the WHERE clause,
> >containing all the userID's that I am interested in?
> >
> >Thanks!
> >
> >--
> >Dotan Cohen
> >
> >http://gibberish.co.il
> >http://what-is-what.com
> >
> >--
> >PHP General Mailing List (http://www.php.net/)
> >To unsubscribe, visit: http://www.php.net/unsub.php
>
> SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
>
> Much smaller than what you proposed in #3, and easier to make if your user is
> list is already an array.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
yeer tai <yeer...@hotmail.com> wrote:
>
>
>select * from table where userID in(1,2,3,etc)
>
>
>
>> From: a...@ashleysheridan.co.uk
>> Date: Tue, 13 Sep 2011 15:29:26 +0100
>> To: dotanco...@gmail.com; php-gene...@lists.php.net
>> Subject: Re: [PHP] Querying a database for 50 users' information: 50
>queries or a WHERE array?
>>
>>
>>
>> Dotan Cohen <dotanco...@gmail.com> wrote:
>>
>> >I have a MySQL database table with about 10,000 rows. If I want to
>> >query for 50 specific users (so no LIMIT ORDER BY) then I seem to
>have
>> >these choices:
>> >
>> >1) SELECT * FROM table
>> >This will pull in all 10,000 rows, not nice!
>> >
>> >2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
>> >userID=".$u); }
>> >This will lead to 50 queries, again not nice! (maybe worse)
>> >
>> >3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
>> >This makes a huge SQL query. However, this is the method that I'm
>using
>> >now.
>> >
>> >Is there some sort of array that can be passed in the WHERE clause,
>> >containing all the userID's that I am interested in?
>> >
>> >Thanks!
>> >
>> >--
>> >Dotan Cohen
>> >
>> >http://gibberish.co.il
>> >http://what-is-what.com
>> >
>> >--
>> >PHP General Mailing List (http://www.php.net/)
>> >To unsubscribe, visit: http://www.php.net/unsub.php
>>
>> SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
>>
>> Much smaller than what you proposed in #3, and easier to make if your
>user is list is already an array.
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>> --
>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
Erm, that's funny that you replied with the exact same answer as I gave, just
top-posted on my reply...
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
--- End Message ---
--- Begin Message ---
Oh no, he stole your internet points!
On Tue, Sep 13, 2011 at 10:44 AM, Ashley Sheridan
<a...@ashleysheridan.co.uk> wrote:
>
>
> yeer tai <yeer...@hotmail.com> wrote:
>
>>
>>
>>select * from table where userID in(1,2,3,etc)
>>
>>
>>
>>> From: a...@ashleysheridan.co.uk
>>> Date: Tue, 13 Sep 2011 15:29:26 +0100
>>> To: dotanco...@gmail.com; php-gene...@lists.php.net
>>> Subject: Re: [PHP] Querying a database for 50 users' information: 50
>>queries or a WHERE array?
>>>
>>>
>>>
>>> Dotan Cohen <dotanco...@gmail.com> wrote:
>>>
>>> >I have a MySQL database table with about 10,000 rows. If I want to
>>> >query for 50 specific users (so no LIMIT ORDER BY) then I seem to
>>have
>>> >these choices:
>>> >
>>> >1) SELECT * FROM table
>>> >This will pull in all 10,000 rows, not nice!
>>> >
>>> >2) foreach ($user as $u) { mysql_query("SELECT * FROM table WHERE
>>> >userID=".$u); }
>>> >This will lead to 50 queries, again not nice! (maybe worse)
>>> >
>>> >3) foreach ($user as $u) { $whereClause+=" OR userID=".$u; }
>>> >This makes a huge SQL query. However, this is the method that I'm
>>using
>>> >now.
>>> >
>>> >Is there some sort of array that can be passed in the WHERE clause,
>>> >containing all the userID's that I am interested in?
>>> >
>>> >Thanks!
>>> >
>>> >--
>>> >Dotan Cohen
>>> >
>>> >http://gibberish.co.il
>>> >http://what-is-what.com
>>> >
>>> >--
>>> >PHP General Mailing List (http://www.php.net/)
>>> >To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>> SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
>>>
>>> Much smaller than what you proposed in #3, and easier to make if your
>>user is list is already an array.
>>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>> --
>>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>
> Erm, that's funny that you replied with the exact same answer as I gave, just
> top-posted on my reply...
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
On Tue, Sep 13, 2011 at 7:29 AM, Ashley Sheridan
<a...@ashleysheridan.co.uk>wrote:
> SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
>
+1. And this is a great place to use implode():
$sql = 'select ... where userID in (' . implode(',', $ids) . ')';
David
--- End Message ---
--- Begin Message ---
On Tue, 2011-09-13 at 09:48 -0700, David Harkness wrote:
> On Tue, Sep 13, 2011 at 7:29 AM, Ashley Sheridan
> <a...@ashleysheridan.co.uk>wrote:
>
> > SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
> >
>
> +1. And this is a great place to use implode():
>
> $sql = 'select ... where userID in (' . implode(',', $ids) . ')';
>
> David
I mentioned that implode earlier, but there is also the underlying
question (which I also asked earlier)... how is he getting the 50 id's
to populate?
here are 2 other ways of skinning the cat:
using an inner join:
select table.* from table inner join othertable on (table.userid =
othertable.userid) where (use the way your getting the 50 id's here);
OR by using a subselect,
select * from table where userid IN (select group_concat(userid,
separator ', ') FROM othertable where (using logic here));
guess it all depends on how you want to do it... but that would make it
1 db query
good luck!
--
Steve Staples
Web Application Developer
--- End Message ---
--- Begin Message ---
Another theoretical approach, given the grey areas, would be to add a
field to your table to indicate these "special" users. I would call
the field "is_awesome" and have it default to zero, because that's
just the way it is. Then you can make your query "SELECT * FROM users
WHERE is_awesome=1". This method might make the code a bit more
manageable as you could modify the users through a CMS rather than
updating a hardcoded array.
Marc
--- End Message ---
--- Begin Message ---
On Tue, Sep 13, 2011 at 2:06 PM, Steve Staples <sstap...@mnsi.net> wrote:
> On Tue, 2011-09-13 at 09:48 -0700, David Harkness wrote:
> > On Tue, Sep 13, 2011 at 7:29 AM, Ashley Sheridan
> > <a...@ashleysheridan.co.uk>wrote:
> >
> > > SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
> > >
> >
> > +1. And this is a great place to use implode():
> >
> > $sql = 'select ... where userID in (' . implode(',', $ids) . ')';
> >
> > David
>
> I mentioned that implode earlier, but there is also the underlying
> question (which I also asked earlier)... how is he getting the 50 id's
> to populate?
>
> here are 2 other ways of skinning the cat:
>
> using an inner join:
> select table.* from table inner join othertable on (table.userid =
> othertable.userid) where (use the way your getting the 50 id's here);
>
> OR by using a subselect,
> select * from table where userid IN (select group_concat(userid,
> separator ', ') FROM othertable where (using logic here));
>
> guess it all depends on how you want to do it... but that would make it
> 1 db query
>
> good luck!
>
>
> --
>
> Steve Staples
> Web Application Developer
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
And this will be faster or at least more efficient with a limit (e.g. limit
50) this way when you have found the 50 users in the "in" statement, you
don't continue iterating through the rest of your data set...
--
The trouble with programmers is that you can never tell what a programmer is
doing until it’s too late. ~Seymour Cray
--- End Message ---
--- Begin Message ---
On Tue, Sep 13, 2011 at 17:29, Ashley Sheridan <a...@ashleysheridan.co.uk>
wrote:
> SELECT * FROM table WHERE userID IN (1,2,3,4,5,etc)
>
> Much smaller than what you proposed in #3, and easier to make if your user is
> list is already an array.
>
Thank you Ash, that is exactly what I was looking for!
--
Dotan Cohen
http://gibberish.co.il
http://what-is-what.com
--- End Message ---
--- Begin Message ---
Is there a way to only change accented characters and not HTML (Example: <p>
</p> <a href =””> </a> )
The syntax
echo htmlentities( stripslashes(mysql_result($whats_new_result,0,"message")) )
. "\r\n";
is doing everything (as I expect). I store breaking news within the database
as HTML formatted text. I am trying to see if a work around is available? Do
I need to do a variety of search / replace to convert the noted characters
above back after htmlentities ?
(I am just starting to get use to accented letters.)
Thanks a lot for your help.
Ron
The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info
--- End Message ---
--- Begin Message ---
You could store the accented characters in your DB if you set
everything to UTF-8, including calling the "SET NAMES utf8" MySQL
command after connecting. I find this much easier than
encoding/decoding.
Marc
--- End Message ---