php-general Digest 12 Aug 2009 14:41:38 -0000 Issue 6281
Topics (messages 296680 through 296702):
Is select_db necessary?
296680 by: Allen McCabe
296681 by: Paul M Foster
296682 by: Tony Marston
296685 by: PJ
296686 by: Tony Marston
296687 by: Jay Blanchard
296688 by: Floyd Resler
296689 by: Robert Cummings
296690 by: Jay Blanchard
296693 by: Colin Guthrie
296694 by: Ralph Deffke
296695 by: Ralph Deffke
296698 by: Martin Scotta
296701 by: Ralph Deffke
296702 by: Ralph Deffke
Re: Embedding foreach loops
296683 by: Ashley Sheridan
296684 by: Ashley Sheridan
Re: Calendar Problem
296691 by: tedd
296692 by: Robert Cummings
296696 by: tedd
296697 by: Martin Scotta
296699 by: Stuart
296700 by: tedd
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 seen different scripts for working with SQL, and most follow the same
method with on difference.
Variables are defined (host, password, etc.)
mysql_connect command
//then, the difference
mysql_select_db command
//back to common
$sql = "SELECT ... "
$result = mysql_query($ql)
Is the database selection necessary, or is that implied with a SELECT or
other SQL command?
--- End Message ---
--- Begin Message ---
On Tue, Aug 11, 2009 at 08:23:21PM -0700, Allen McCabe wrote:
> I have seen different scripts for working with SQL, and most follow the same
> method with on difference.
>
> Variables are defined (host, password, etc.)
> mysql_connect command
>
> //then, the difference
>
> mysql_select_db command
>
> //back to common
>
> $sql = "SELECT ... "
> $result = mysql_query($ql)
>
> Is the database selection necessary, or is that implied with a SELECT or
> other SQL command?
All major SQL DBMSes can have multiple databases available. A given
database may contain a variety of tables. If you simply start firing SQL
commands at a DBMS, it won't know which database to look in unless you
tell it. By contrast, the connection process in PostgreSQL must include
a database; there is no separate database selection function call.
Paul
--
Paul M. Foster
--- End Message ---
--- Begin Message ---
"Paul M Foster" <pa...@quillandmouse.com> wrote in message
news:20090812035618.gd2...@quillandmouse.com...
> On Tue, Aug 11, 2009 at 08:23:21PM -0700, Allen McCabe wrote:
>
>> I have seen different scripts for working with SQL, and most follow the
>> same
>> method with on difference.
>>
>> Variables are defined (host, password, etc.)
>> mysql_connect command
>>
>> //then, the difference
>>
>> mysql_select_db command
>>
>> //back to common
>>
>> $sql = "SELECT ... "
>> $result = mysql_query($ql)
>>
>> Is the database selection necessary, or is that implied with a SELECT or
>> other SQL command?
>
> All major SQL DBMSes can have multiple databases available. A given
> database may contain a variety of tables. If you simply start firing SQL
> commands at a DBMS, it won't know which database to look in unless you
> tell it. By contrast, the connection process in PostgreSQL must include
> a database; there is no separate database selection function call.
This is not totally accurate. With MySQL you connect to a server which is a
container for one or more databases, so you need select_db in order to
identify the current database name.
With PostgreSQL you connect to a database which is a container for one or
more schemas, so you need to issue the "SET search_path TO <schema>" command
in order to identify the current schema.
Oracle is the same in that you connect to a server which is a container for
one or more databases, and unless you give every table a public synonym you
must use the "ALTER SESSION SET CURRENT_SCHEMA = <schema>" command to
identify the current schema.
In all these cases this will allow you to issue an sql query which contains
table names which do not have to be qualified with their database/schema
names. If you wish to refer to a table which is not in the current
database/schema then you must include the database/schema name.
I consider the use of the term "schema", as used by PostgreSQL and Oracle,
to be inaccurate in that a database table is subordinate to a database, not
a schema. That is why it is called a "database" table and not a "schema"
table.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
--- End Message ---
--- Begin Message ---
Paul M Foster wrote:
> On Tue, Aug 11, 2009 at 08:23:21PM -0700, Allen McCabe wrote:
>
>
>> I have seen different scripts for working with SQL, and most follow the same
>> method with on difference.
>>
>> Variables are defined (host, password, etc.)
>> mysql_connect command
>>
>> //then, the difference
>>
>> mysql_select_db command
>>
>> //back to common
>>
>> $sql = "SELECT ... "
>> $result = mysql_query($ql)
>>
>> Is the database selection necessary, or is that implied with a SELECT or
>> other SQL command?
>>
>
> All major SQL DBMSes can have multiple databases available. A given
> database may contain a variety of tables. If you simply start firing SQL
> commands at a DBMS, it won't know which database to look in unless you
> tell it. By contrast, the connection process in PostgreSQL must include
> a database; there is no separate database selection function call.
>
> Paul
>
I seem to recall from the manual, that once you have done mysql_connect
, any subsequent queries will be directed at the same db until another
mysql_connect points to another db. I repeat the call with every query
as a precaution.
I'm not expert, but I thought I'd offer my observation and am open to
correction. ;-)
PJ
--- End Message ---
--- Begin Message ---
"PJ" <af.gour...@videotron.ca> wrote in message
news:4a82aa58.2020...@videotron.ca...
> Paul M Foster wrote:
>> On Tue, Aug 11, 2009 at 08:23:21PM -0700, Allen McCabe wrote:
>>
>>
>>> I have seen different scripts for working with SQL, and most follow the
>>> same
>>> method with on difference.
>>>
>>> Variables are defined (host, password, etc.)
>>> mysql_connect command
>>>
>>> //then, the difference
>>>
>>> mysql_select_db command
>>>
>>> //back to common
>>>
>>> $sql = "SELECT ... "
>>> $result = mysql_query($ql)
>>>
>>> Is the database selection necessary, or is that implied with a SELECT or
>>> other SQL command?
>>>
>>
>> All major SQL DBMSes can have multiple databases available. A given
>> database may contain a variety of tables. If you simply start firing SQL
>> commands at a DBMS, it won't know which database to look in unless you
>> tell it. By contrast, the connection process in PostgreSQL must include
>> a database; there is no separate database selection function call.
>>
>> Paul
>>
> I seem to recall from the manual, that once you have done mysql_connect
> , any subsequent queries will be directed at the same db until another
> mysql_connect points to another db. I repeat the call with every query
> as a precaution.
> I'm not expert, but I thought I'd offer my observation and am open to
> correction. ;-)
> PJ
This only works if you specify a database name in the call to
mysqli_connect(). If provided (it is optional) it identifies the default
database name for all subsequent queries. If, like me, you have multiple
databases available, then you need to use select_db in order to switch the
default database from one to another.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org
--- End Message ---
--- Begin Message ---
[snip]
Is the database selection necessary, or is that implied with a SELECT or
other SQL command?
[/snip]
It depends on the database (as you have seen in many of the responses),
but there is a way to keep from doing this if the database is ANSI
compliant using proper SQL syntax;
SELECT a.foo, a.bar
FROM myDatabase.myTable a
WHERE you set other conditions here
All that is required is that you establish a connection to a server.
--- End Message ---
--- Begin Message ---
mysql_select_db is not necessary but it does make writing queries
easier since you don't have to specify which database in each query.
Take care,
Floyd
On Aug 11, 2009, at 11:23 PM, Allen McCabe wrote:
I have seen different scripts for working with SQL, and most follow
the same
method with on difference.
Variables are defined (host, password, etc.)
mysql_connect command
//then, the difference
mysql_select_db command
//back to common
$sql = "SELECT ... "
$result = mysql_query($ql)
Is the database selection necessary, or is that implied with a
SELECT or
other SQL command?
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
[snip]
Is the database selection necessary, or is that implied with a SELECT or
other SQL command?
[/snip]
It depends on the database (as you have seen in many of the responses),
but there is a way to keep from doing this if the database is ANSI
compliant using proper SQL syntax;
SELECT a.foo, a.bar
FROM myDatabase.myTable a
WHERE you set other conditions here
All that is required is that you establish a connection to a server.
If I recall correctly, this will cause issues with replication in
MySQL... insofar as you perform amodifying query.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
[snip]
Jay Blanchard wrote:
> [snip]
> Is the database selection necessary, or is that implied with a SELECT
or
> other SQL command?
> [/snip]
>
> It depends on the database (as you have seen in many of the
responses),
> but there is a way to keep from doing this if the database is ANSI
> compliant using proper SQL syntax;
>
> SELECT a.foo, a.bar
> FROM myDatabase.myTable a
> WHERE you set other conditions here
>
> All that is required is that you establish a connection to a server.
If I recall correctly, this will cause issues with replication in
MySQL... insofar as you perform amodifying query.
[/snip]
You're correct with regards to queries that modify on replicated
systems. If all you're doing is gathering data then this will work just
fine, is somewhat self-documenting (especially in lengthier code
containers), and very flexible. It also leaves the selection in the
database's hands, and as we almost always say, "let the database do the
work when it can".
If you are not using replicated systems you can set up your modifying
queries the same way.
--- End Message ---
--- Begin Message ---
'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble:
Jay Blanchard wrote:
SELECT a.foo, a.bar
FROM myDatabase.myTable a
WHERE you set other conditions here
All that is required is that you establish a connection to a server.
If I recall correctly, this will cause issues with replication in
MySQL... insofar as you perform amodifying query.
[/snip]
You're correct with regards to queries that modify on replicated
systems. If all you're doing is gathering data then this will work just
fine, is somewhat self-documenting (especially in lengthier code
containers), and very flexible. It also leaves the selection in the
database's hands, and as we almost always say, "let the database do the
work when it can".
I'm interested to know why you consider this to be very flexible and how
this leaves the selection in the database's hands?
If I were to implement this and they try some destructive testing/demo
on a sacrificial database, I'd have to use a whole other server instance
(as all the queries would hardcode in the db name).
Is it not more flexible if you omit the table name in every single query
and specify it once in your bootstrap/connection code? Thus doing tests
on other dbs etc. is a pretty simple switch of the connection code.
Also telling the db engine what database you want to use in every query
is not, IMO, leaving the selection in the the database's hands.
Just curious as to the rationale here :)
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--- End Message ---
--- Begin Message ---
here a basic background to this question.
all databases are build from various module bases. one module is the
database itself prosessing eg. the sql's another module is the database
connectivity. e.g. mySQL has a ability to connect thru ADO, .NET and an
server via IP.
MySQL supports unlimited databases comtaining tables. so from the point of
the database u have always to selct the database and then to the table.
however, if u study the various Database extensions u will find functions
(eg. mysql_db_query() ) where u point the database in the function call
while others don't (eg. mysql_query() ) on those u have to do a db select
first because the function itself doesn't do it, while mysql_db_connect()
does.
so if we know that now, we are coming to the question, why are database
extensions do have those two types of processing a sql statement?
the answer is: speed ! while those commands with a pointing out the database
do internally a select of the database they do it every time on each call.
if u have a application which does a lot of stuff at the same time other
then just select statement, this comes into consideration. it saves time to
do one select_db first and then 50 just raw sql's to that database.
now after dumping that much stuff on u, it depends on ur design if u need a
select_db first or not.
hope that helps
Ralph
ralph_def...@yahoo.de
"Allen McCabe" <allenmcc...@gmail.com> wrote in message
news:657acef20908112023y222de6f4q63e64cd1e2785...@mail.gmail.com...
> I have seen different scripts for working with SQL, and most follow the
same
> method with on difference.
>
> Variables are defined (host, password, etc.)
> mysql_connect command
>
> //then, the difference
>
> mysql_select_db command
>
> //back to common
>
> $sql = "SELECT ... "
> $result = mysql_query($ql)
>
> Is the database selection necessary, or is that implied with a SELECT or
> other SQL command?
>
--- End Message ---
--- Begin Message ---
I agree totally, are we not dicussing speed issues all the time? and then we
recommend a code doing an unessesary job on every call?
an ANSI selct db in the sql forces any database to run the internal select
db because there would be no check if the databse is the current one.
because, databasedevelopers can espext some smartness of us, the
programmers. its a lot off stuff to do for the database to select a
database. for shure, the database leafs that IN OUR hand to avoid to force
time consuming server resources.
ralph
ralph_def...@yahoo.de
"Colin Guthrie" <gm...@colin.guthr.ie> wrote in message
news:h5ug1h$tj...@ger.gmane.org...
> 'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble:
> > Jay Blanchard wrote:
> >> SELECT a.foo, a.bar
> >> FROM myDatabase.myTable a
> >> WHERE you set other conditions here
> >>
> >> All that is required is that you establish a connection to a server.
> >
> > If I recall correctly, this will cause issues with replication in
> > MySQL... insofar as you perform amodifying query.
> > [/snip]
> >
> > You're correct with regards to queries that modify on replicated
> > systems. If all you're doing is gathering data then this will work just
> > fine, is somewhat self-documenting (especially in lengthier code
> > containers), and very flexible. It also leaves the selection in the
> > database's hands, and as we almost always say, "let the database do the
> > work when it can".
>
> I'm interested to know why you consider this to be very flexible and how
> this leaves the selection in the database's hands?
>
> If I were to implement this and they try some destructive testing/demo
> on a sacrificial database, I'd have to use a whole other server instance
> (as all the queries would hardcode in the db name).
>
> Is it not more flexible if you omit the table name in every single query
> and specify it once in your bootstrap/connection code? Thus doing tests
> on other dbs etc. is a pretty simple switch of the connection code.
>
> Also telling the db engine what database you want to use in every query
> is not, IMO, leaving the selection in the the database's hands.
>
> Just curious as to the rationale here :)
>
> Col
>
>
>
>
> --
>
> Colin Guthrie
> gmane(at)colin.guthr.ie
> http://colin.guthr.ie/
>
> Day Job:
> Tribalogic Limited [http://www.tribalogic.net/]
> Open Source:
> Mandriva Linux Contributor [http://www.mandriva.com/]
> PulseAudio Hacker [http://www.pulseaudio.org/]
> Trac Hacker [http://trac.edgewall.org/]
>
--- End Message ---
--- Begin Message ---
Wed, Aug 12, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de> wrote:
> I agree totally, are we not dicussing speed issues all the time? and then
> we
> recommend a code doing an unessesary job on every call?
>
> an ANSI selct db in the sql forces any database to run the internal select
> db because there would be no check if the databse is the current one.
> because, databasedevelopers can espext some smartness of us, the
> programmers. its a lot off stuff to do for the database to select a
> database. for shure, the database leafs that IN OUR hand to avoid to force
> time consuming server resources.
>
> ralph
> ralph_def...@yahoo.de
>
> "Colin Guthrie" <gm...@colin.guthr.ie> wrote in message
> news:h5ug1h$tj...@ger.gmane.org...
> > 'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble:
> > > Jay Blanchard wrote:
> > >> SELECT a.foo, a.bar
> > >> FROM myDatabase.myTable a
> > >> WHERE you set other conditions here
> > >>
> > >> All that is required is that you establish a connection to a server.
> > >
> > > If I recall correctly, this will cause issues with replication in
> > > MySQL... insofar as you perform amodifying query.
> > > [/snip]
> > >
> > > You're correct with regards to queries that modify on replicated
> > > systems. If all you're doing is gathering data then this will work just
> > > fine, is somewhat self-documenting (especially in lengthier code
> > > containers), and very flexible. It also leaves the selection in the
> > > database's hands, and as we almost always say, "let the database do the
> > > work when it can".
> >
> > I'm interested to know why you consider this to be very flexible and how
> > this leaves the selection in the database's hands?
> >
> > If I were to implement this and they try some destructive testing/demo
> > on a sacrificial database, I'd have to use a whole other server instance
> > (as all the queries would hardcode in the db name).
> >
> > Is it not more flexible if you omit the table name in every single query
> > and specify it once in your bootstrap/connection code? Thus doing tests
> > on other dbs etc. is a pretty simple switch of the connection code.
> >
> > Also telling the db engine what database you want to use in every query
> > is not, IMO, leaving the selection in the the database's hands.
> >
> > Just curious as to the rationale here :)
> >
> > Col
> >
> >
> >
> >
> > --
> >
> > Colin Guthrie
> > gmane(at)colin.guthr.ie
> > http://colin.guthr.ie/
> >
> > Day Job:
> > Tribalogic Limited [http://www.tribalogic.net/]
> > Open Source:
> > Mandriva Linux Contributor [http://www.mandriva.com/]
> > PulseAudio Hacker [http://www.pulseaudio.org/]
> > Trac Hacker [http://trac.edgewall.org/]
> >
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
<?php
$link = mysql_connect( /* settings */);
mysql_select_db( 'database', $link);
$result = mysql_query( 'SELECT * FROM <table>', $link );
What SQL was sent to the database?
Looking at bin logs I've found this.
1. use database => mysql_select_db
2. use database: SELECT * FROM <table> => mysql_query
The DB is usually a common bottle-neck for most applications.
You can have several webservers, but can't do that with the DB... of course,
you can have multiples slaves but just 1 master.
is this the best way to send queries?
What's the better and faster way?
--
Martin Scotta
--- End Message ---
--- Begin Message ---
as i said earlier: on db level there is always al select db done, doing this
on higer level layers (the database extension) consumes time. or why do
extension have the two ways of functions? to make our live more difficult?
on a ANSI sql the sql interpreter time is increased! unnessarylie
ralph_def...@yahoo.de
"Martin Scotta" <martinsco...@gmail.com> wrote in message
news:6445d94e0908120718g6c5bf368tacf8bbad127b5...@mail.gmail.com...
> Wed, Aug 12, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de> wrote:
>
> > I agree totally, are we not dicussing speed issues all the time? and
then
> > we
> > recommend a code doing an unessesary job on every call?
> >
> > an ANSI selct db in the sql forces any database to run the internal
select
> > db because there would be no check if the databse is the current one.
> > because, databasedevelopers can espext some smartness of us, the
> > programmers. its a lot off stuff to do for the database to select a
> > database. for shure, the database leafs that IN OUR hand to avoid to
force
> > time consuming server resources.
> >
> > ralph
> > ralph_def...@yahoo.de
> >
> > "Colin Guthrie" <gm...@colin.guthr.ie> wrote in message
> > news:h5ug1h$tj...@ger.gmane.org...
> > > 'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and
gimble:
> > > > Jay Blanchard wrote:
> > > >> SELECT a.foo, a.bar
> > > >> FROM myDatabase.myTable a
> > > >> WHERE you set other conditions here
> > > >>
> > > >> All that is required is that you establish a connection to a
server.
> > > >
> > > > If I recall correctly, this will cause issues with replication in
> > > > MySQL... insofar as you perform amodifying query.
> > > > [/snip]
> > > >
> > > > You're correct with regards to queries that modify on replicated
> > > > systems. If all you're doing is gathering data then this will work
just
> > > > fine, is somewhat self-documenting (especially in lengthier code
> > > > containers), and very flexible. It also leaves the selection in the
> > > > database's hands, and as we almost always say, "let the database do
the
> > > > work when it can".
> > >
> > > I'm interested to know why you consider this to be very flexible and
how
> > > this leaves the selection in the database's hands?
> > >
> > > If I were to implement this and they try some destructive testing/demo
> > > on a sacrificial database, I'd have to use a whole other server
instance
> > > (as all the queries would hardcode in the db name).
> > >
> > > Is it not more flexible if you omit the table name in every single
query
> > > and specify it once in your bootstrap/connection code? Thus doing
tests
> > > on other dbs etc. is a pretty simple switch of the connection code.
> > >
> > > Also telling the db engine what database you want to use in every
query
> > > is not, IMO, leaving the selection in the the database's hands.
> > >
> > > Just curious as to the rationale here :)
> > >
> > > Col
> > >
> > >
> > >
> > >
> > > --
> > >
> > > Colin Guthrie
> > > gmane(at)colin.guthr.ie
> > > http://colin.guthr.ie/
> > >
> > > Day Job:
> > > Tribalogic Limited [http://www.tribalogic.net/]
> > > Open Source:
> > > Mandriva Linux Contributor [http://www.mandriva.com/]
> > > PulseAudio Hacker [http://www.pulseaudio.org/]
> > > Trac Hacker [http://trac.edgewall.org/]
> > >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> <?php
>
> $link = mysql_connect( /* settings */);
> mysql_select_db( 'database', $link);
> $result = mysql_query( 'SELECT * FROM <table>', $link );
>
> What SQL was sent to the database?
>
> Looking at bin logs I've found this.
>
> 1. use database => mysql_select_db
> 2. use database: SELECT * FROM <table> => mysql_query
>
> The DB is usually a common bottle-neck for most applications.
> You can have several webservers, but can't do that with the DB... of
course,
> you can have multiples slaves but just 1 master.
>
> is this the best way to send queries?
> What's the better and faster way?
>
> --
> Martin Scotta
>
--- End Message ---
--- Begin Message ---
what are telling the logs on that code?
<?php
$link = mysql_connect( /* settings */);
mysql_select_db( 'database', $link);
$result = mysql_query( 'SELECT * FROM <table>', $link );
$result = mysql_query( 'SELECT * FROM <anothertable>', $link );
$result = mysql_query( 'SELECT * FROM <anothertable>', $link );
$result = mysql_query( 'SELECT * FROM <anothertable>', $link );
$result = mysql_query( 'SELECT * FROM <anothertable>', $link );
$result = mysql_query( 'SELECT * FROM <table>', $link );
would be interesting to see.
I personaly woudn't spend the time on logs, a computer is logical, I try to be
logical, and I would
try to create code which is logical speedy. I expect the database kernel
programmer the same.
I think then we are on the secure side.
ralph_def...@yahoo.de
________________________________
Von: Martin Scotta <martinsco...@gmail.com>
An: Ralph Deffke <ralph_def...@yahoo.de>
CC: php-gene...@lists.php.net
Gesendet: Mittwoch, den 12. August 2009, 16:18:01 Uhr
Betreff: Re: [PHP] Re: Is select_db necessary?
Wed, Aug 12, 2009 at 10:37 AM, Ralph Deffke <ralph_def...@yahoo.de> wrote:
>I agree totally, are we not dicussing speed issues all the time? and then we
>>recommend a code doing an unessesary job on every call?
>
>>an ANSI selct db in the sql forces any database to run the internal select
>>db because there would be no check if the databse is the current one.
>>because, databasedevelopers can espext some smartness of us, the
>>programmers. its a lot off stuff to do for the database to select a
>>database. for shure, the database leafs that IN OUR hand to avoid to force
>>time consuming server resources.
>
>>ralph
>ralph_def...@yahoo.de
>
>>"Colin Guthrie" <gm...@colin.guthr.ie> wrote in message
>>news:h5ug1h$tj...@ger.gmane.org...
>
>> 'Twas brillig, and Jay Blanchard at 12/08/09 13:53 did gyre and gimble:
>>> > Jay Blanchard wrote:
>>> >> SELECT a.foo, a.bar
>>> >> FROM myDatabase.myTable a
>>> >> WHERE you set other conditions here
>>> >>
>>> >> All that is required is that you establish a connection to a server.
>>> >
>>> > If I recall correctly, this will cause issues with replication in
>>> > MySQL... insofar as you perform amodifying query.
>>> > [/snip]
>>> >
>>> > You're correct with regards to queries that modify on replicated
>>> > systems. If all you're doing is gathering data then this will work just
>>> > fine, is somewhat self-documenting (especially in lengthier code
>>> > containers), and very flexible. It also leaves the selection in the
>>> > database's hands, and as we almost always say, "let the database do the
>>> > work when it can".
>>>
>>> I'm interested to know why you consider this to be very flexible and how
>>> this leaves the selection in the database's hands?
>>>
>>> If I were to implement this and they try some destructive testing/demo
>>> on a sacrificial database, I'd have to use a whole other server instance
>>> (as all the queries would hardcode in the db name).
>>>
>>> Is it not more flexible if you omit the table name in every single query
>>> and specify it once in your bootstrap/connection code? Thus doing tests
>>> on other dbs etc. is a pretty simple switch of the connection code.
>>>
>>> Also telling the db engine what database you want to use in every query
>>> is not, IMO, leaving the selection in the the database's hands.
>>>
>>> Just curious as to the rationale here :)
>>>
>>> Col
>>>
>>>
>>>
>>>
>>> --
>>>
>>> Colin Guthrie
>>> gmane(at)colin.guthr.ie
>>> http://colin.guthr.ie/
>>>
>>> Day Job:
>>> Tribalogic Limited [http://www.tribalogic.net/]
>>> Open Source:
>>> Mandriva Linux Contributor [http://www.mandriva.com/]
>>> PulseAudio Hacker [http://www.pulseaudio.org/]
>>> Trac Hacker [http://trac.edgewall.org/]
>>>
>
>
>
>>--
>>PHP General Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>
>
<?php
$link = mysql_connect( /* settings */);
mysql_select_db( 'database', $link);
$result = mysql_query( 'SELECT * FROM <table>', $link );
What SQL was sent to the database?
Looking at bin logs I've found this.
1. use database => mysql_select_db
2. use database: SELECT * FROM <table> => mysql_query
The DB is usually a common bottle-neck for most applications.
You can have several webservers, but can't do that with the DB... of course,
you can have multiples slaves but just 1 master.
is this the best way to send queries?
What's the better and faster way?
--
Martin Scotta
--- End Message ---
--- Begin Message ---
On Tue, 2009-08-11 at 16:00 -0400, Eddie Drapkin wrote:
> On Tue, Aug 11, 2009 at 3:56 PM, tedd<tedd.sperl...@gmail.com> wrote:
> > At 12:44 PM -0700 8/11/09, Ben Dunlap wrote:
> >>
> >> This is probably flame-war tinder, so I'll try to tread more delicately in
> >> the future. Next you know we'll be on the ternary operator and which is
> >> better, Mac or Windows. ;-)
> >>
> >> Ben
> >
> > That was won long ago, it's Mac. :-)
> >
> > Cheers,
> >
> > tedd
> >
> > --
> > -------
> > http://sperling.com http://ancientstones.com http://earthstones.com
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
> If by Mac you mean Linux, you're entirely correct.
>
Linux +100
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
On Tue, 2009-08-11 at 16:23 -0400, Rick Duval wrote:
> OK, first guys, I'm sorry to have to do this but I can't get off this list!!!
>
> I've followed the instructions on a couple of occasions (the ones at
> the bottom of every email):
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
>
> Been There, done that. I can't get off the list!!! I use Gmail and I
> use an an alias as well, tried them both, still on the list. No reply
> from Majordomo.
>
> Yes, I've check my spam filter for a unsubscribe confirmation (if it
> sends one which I presume it's supposed to).
>
> Headers tell me that this list is "php-gene...@lists.php.net". Sent
> the unsubscribe emails. No replies.
>
> Again. I apologize but have no idea what to do to get off this list!
> THis is the only list server I can't seem to get off of.
>
> Help!
>
>
> On Mon, Aug 10, 2009 at 6:04 PM, John
> Butler<govinda.webdnat...@gmail.com> wrote:
> >> I can't seem to get my foreach loops to work, will PHP parse embedded
> >> loops?
> >
> > yes.
> >
> >> Is this something I need to have in a database to work?
> >
> > no, you can do it with the arrays... but it may be easier to work with over
> > the long run if that data was in a db.
> >
> > Anyway right after you finish creating the array and it's embedded arrays,
> > in your code, then add this:
> > var_dump($shows); //--so you can see what you just created. If it looks
> > right, THEN go on bothering to try and parse it with your (embedded)
> > foreach's {
> >
> > ------------
> > John Butler (Govinda)
> > govinda.webdnat...@gmail.com
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> > ---------------------------------This message has been scanned for
> > viruses and dangerous content byAccurate Anti-Spam Technologies.
> > www.AccurateAntiSpam.com
> >
> >
>
Use the unsubscribe email address that's in the header (this is very
different from the footer) of every email from the list.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--- End Message ---
--- Begin Message ---
At 4:08 PM -0400 8/11/09, Robert Cummings wrote:
tedd wrote:
Hi gang:
I want to show the dates for all Fridays +-30 days from a specific date.
For example, given today's date (8/11/2009) the Fridays that fall
+-30 days are July 17, July 24, July 31, Aug 7, Aug 14, Aug 21, Aug
28, and Sept 4.
I'm curious, how would you guys solve this?
<?php
$fridays = array();
for( $i = -30; $i <= 30; $i++ )
{
$mod = $i < 0 ? $i : '+'.$i;
$time = strtotime( $mod.' day' );
if( date( 'D', $time ) == 'Fri' )
{
$fridays[] = date( 'Y-m-d', $time );
}
}
print_r( $fridays );
?>
Cheers,
Rob.
Rob:
That's slick -- you never let me down with your simplicity and creativity.
My solution was to find the next Friday and then cycle through +-28
days (four weeks) from that date, like so:
<?php
$fridays = array();
for( $i = 1; $i <= 7; $i++ )
{
$time = strtotime( $i . ' day' );
if( date( 'D', $time ) == 'Fri' )
{
$start = 28 - $i;
$end = 28 + $i;
}
}
for( $i = -$start; $i <= $end; $i += 7 )
{
$time = strtotime( $i . ' day' );
$fridays[] = date( 'Y-m-d', $time );
}
print_r( $fridays );
?>
Your solution had 61 iterations (for loop) while mind had only 21, so
mine's a bit faster. Here's the comparison:
http://php1.net/b/fridays/
But I'll use your solution -- it's more elegant.
Thanks for the code,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
tedd wrote:
At 4:08 PM -0400 8/11/09, Robert Cummings wrote:
tedd wrote:
Hi gang:
I want to show the dates for all Fridays +-30 days from a specific date.
For example, given today's date (8/11/2009) the Fridays that fall
+-30 days are July 17, July 24, July 31, Aug 7, Aug 14, Aug 21, Aug
28, and Sept 4.
I'm curious, how would you guys solve this?
<?php
$fridays = array();
for( $i = -30; $i <= 30; $i++ )
{
$mod = $i < 0 ? $i : '+'.$i;
$time = strtotime( $mod.' day' );
if( date( 'D', $time ) == 'Fri' )
{
$fridays[] = date( 'Y-m-d', $time );
}
}
print_r( $fridays );
?>
Cheers,
Rob.
Rob:
That's slick -- you never let me down with your simplicity and creativity.
My solution was to find the next Friday and then cycle through +-28
days (four weeks) from that date, like so:
<?php
$fridays = array();
for( $i = 1; $i <= 7; $i++ )
{
$time = strtotime( $i . ' day' );
if( date( 'D', $time ) == 'Fri' )
{
$start = 28 - $i;
$end = 28 + $i;
}
}
for( $i = -$start; $i <= $end; $i += 7 )
{
$time = strtotime( $i . ' day' );
$fridays[] = date( 'Y-m-d', $time );
}
print_r( $fridays );
?>
Your solution had 61 iterations (for loop) while mind had only 21, so
mine's a bit faster. Here's the comparison:
http://php1.net/b/fridays/
But I'll use your solution -- it's more elegant.
Thanks for the code,
tedd
I think Shawn McKenzie's is the best. It seems his would take at most 12
iterations.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--- End Message ---
--- Begin Message ---
At 4:08 PM -0400 8/11/09, Robert Cummings wrote:
I think Shawn McKenzie's is the best. It seems his would take at
most 12 iterations.
Cheers,
Rob.
Rob:
For some reason I did not see/consider Shawn's solutions -- sorry Shawn.
However, it appears that mine is still the fastest in most test. Check this:
http://php1.net/b/fridays/
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---
--- Begin Message ---
On Wed, Aug 12, 2009 at 10:25 AM, Robert Cummings <rob...@interjinn.com>wrote:
>
>
> tedd wrote:
>
>> At 4:08 PM -0400 8/11/09, Robert Cummings wrote:
>>
>>> tedd wrote:
>>>
>>>> Hi gang:
>>>>
>>>> I want to show the dates for all Fridays +-30 days from a specific date.
>>>>
>>>> For example, given today's date (8/11/2009) the Fridays that fall +-30
>>>> days are July 17, July 24, July 31, Aug 7, Aug 14, Aug 21, Aug 28, and Sept
>>>> 4.
>>>>
>>>> I'm curious, how would you guys solve this?
>>>>
>>> <?php
>>>
>>> $fridays = array();
>>> for( $i = -30; $i <= 30; $i++ )
>>> {
>>> $mod = $i < 0 ? $i : '+'.$i;
>>>
>>> $time = strtotime( $mod.' day' );
>>>
>>> if( date( 'D', $time ) == 'Fri' )
>>> {
>>> $fridays[] = date( 'Y-m-d', $time );
>>> }
>>> }
>>>
>>> print_r( $fridays );
>>>
>>> ?>
>>>
>>> Cheers,
>>> Rob.
>>>
>>
>> Rob:
>>
>> That's slick -- you never let me down with your simplicity and creativity.
>>
>> My solution was to find the next Friday and then cycle through +-28 days
>> (four weeks) from that date, like so:
>>
>> <?php
>> $fridays = array();
>>
>> for( $i = 1; $i <= 7; $i++ )
>> {
>> $time = strtotime( $i . ' day' );
>> if( date( 'D', $time ) == 'Fri' )
>> {
>> $start = 28 - $i;
>> $end = 28 + $i;
>> }
>> }
>>
>> for( $i = -$start; $i <= $end; $i += 7 )
>> {
>> $time = strtotime( $i . ' day' );
>> $fridays[] = date( 'Y-m-d', $time );
>> }
>>
>> print_r( $fridays );
>> ?>
>>
>> Your solution had 61 iterations (for loop) while mind had only 21, so
>> mine's a bit faster. Here's the comparison:
>>
>> http://php1.net/b/fridays/
>>
>> But I'll use your solution -- it's more elegant.
>>
>> Thanks for the code,
>>
>> tedd
>>
>
> I think Shawn McKenzie's is the best. It seems his would take at most 12
> iterations.
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Hi all
This is my point of view.
I try to stay the most legible and simple as possible.
@tedd: can you benchmark this script too? usualy legibility > performance
<?php
$fridays = array(); # I'll store the friday here
$day = strtotime('-1 month', time() ); # let's start at one month ago
while( 5 != date('w', $day)) # advance to a friday
$day = strtotime('+1 day', $day);
# I'll stop when $day where ahead one month from today
$end = strtotime( '+1 month', time() );
do{
$friday[] = date('Y-m-d', $day); # store the friday
$day = strtotime('+1 week', $day); # advance one week
} while( $day < $end );
# job's done!
print_r( $friday );
--
Martin Scotta
--- End Message ---
--- Begin Message ---
2009/8/12 tedd <tedd.sperl...@gmail.com>:
>>> At 4:08 PM -0400 8/11/09, Robert Cummings wrote:
>>
>> I think Shawn McKenzie's is the best. It seems his would take at most 12
>> iterations.
>>
>> Cheers,
>> Rob.
>
> Rob:
>
> For some reason I did not see/consider Shawn's solutions -- sorry Shawn.
>
> However, it appears that mine is still the fastest in most test. Check this:
>
> http://php1.net/b/fridays/
Bit late to this party, but give this a whizz...
http://dev.stut.net/php/fridays.php
-Stuart
--
http://stut.net/
--- End Message ---
--- Begin Message ---
At 11:03 AM -0300 8/12/09, Martin Scotta wrote:
Hi all
This is my point of view.
I try to stay the most legible and simple as possible.
@tedd: can you benchmark this script too? usualy legibility > performance
<?php
$fridays = array(); # I'll store the friday here
$day = strtotime('-1 month', time() ); # let's start at one month ago
while( 5 != date('w', $day)) # advance to a friday
$day = strtotime('+1 day', $day);
# I'll stop when $day where ahead one month from today
$end = strtotime( '+1 month', time() );
do{
$friday[] = date('Y-m-d', $day); # store the friday
$day = strtotime('+1 week', $day); # advance one week
} while( $day < $end );
# job's done!
print_r( $friday );
--
Martin Scotta
Martin:
It's included here:
http://php1.net/b/fridays/
Works great -- thanks.
As Shawn said "Many ways to skin a cat"
As Jeff Foxworthy added "But he ain't going to like any of them!"
Cheers,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
--- End Message ---