php-general Digest 31 Mar 2009 10:51:48 -0000 Issue 6041

Topics (messages 290869 through 290883):

Re: PHP + MySQL - Load last inserts
        290869 by: haliphax
        290870 by: Chris

formulate nested select
        290871 by: PJ
        290872 by: Chris
        290875 by: Jim Lucas
        290876 by: Chris

5.2.9 changes - phpwiki
        290873 by: Charles Sprickman
        290878 by: Michael A. Peters

Re: Problem with header();
        290874 by: Phpster

Working in UTF-8 - BOM trouble
        290877 by: Merlin Morgenstern
        290882 by: Jan G.B.
        290883 by: Andrea Giammarchi

GSoC - XDebug Profiling Web Frontend
        290879 by: Alpár Török

thread question
        290880 by: Toke Herkild
        290881 by: Carlos Medina

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 Mon, Mar 30, 2009 at 5:10 PM, Chris <dmag...@gmail.com> wrote:
> haliphax wrote:
>>
>> On Mon, Mar 30, 2009 at 9:13 AM, Sebastian Muszytowski
>> <s.muszytow...@googlemail.com> wrote:
>>>
>>> haliphax schrieb:
>>>>>
>>>>> [..cut...]
>>>>
>>>> Except when your primary key value rolls over, or fills a gap between
>>>> two other rows that was left when a row was deleted/moved/etc... there
>>>> has got to be a better way than grabbing rows in descending order
>>>> based on the auto_increment value.
>>>>
>>>> Are you doing the inserts one at a time? If so, why not just use code
>>>> to remember what you put in the DB?
>>>>
>>> I do the inserts one at a time, i could use code to remember but i think
>>> it
>>> would be very slow when i have too much users.
>>>
>>> The second thing that aware me from doing this is, why use/build
>>> ressources
>>> when you could use others? i think why should i use and add another
>>> system?
>>> I work with mysql already and when php+mysql have the function i need
>>> it's
>>> better and i don't waste ressources :)
>>
>> Insert 100 records. Delete 50 of them at random. Now do your "grab the
>> last few records and sort them in descending order" trick and see
>> where it gets you.
>
> Mysql does not re-use id's (nor does any other db as far as I'm aware, and
> nor should it). I don't know where you got that idea from.
>
> mysql> create table test (id int auto_increment not null primary key, name
> text);
> Query OK, 0 rows affected (0.12 sec)
>
> mysql> insert into test(name) values
> ('one'),('two'),('three'),('four'),('five'),('six'),('seven'),('eight'),('nine'),('ten');
> Query OK, 10 rows affected (0.00 sec)
> Records: 10  Duplicates: 0  Warnings: 0
>
> mysql> select * from test;
> +----+-------+
> | id | name  |
> +----+-------+
> |  1 | one   |
> |  2 | two   |
> |  3 | three |
> |  4 | four  |
> |  5 | five  |
> |  6 | six   |
> |  7 | seven |
> |  8 | eight |
> |  9 | nine  |
> | 10 | ten   |
> +----+-------+
> 10 rows in set (0.00 sec)
>
> mysql> delete from test where id in (1,3,7);
> Query OK, 3 rows affected (0.00 sec)
>
> mysql> insert into test(name) values('eleven');
> Query OK, 1 row affected (0.00 sec)
>
> mysql> select * from test;
> +----+--------+
> | id | name   |
> +----+--------+
> |  2 | two    |
> |  4 | four   |
> |  5 | five   |
> |  6 | six    |
> | 11 | eleven |
> |  8 | eight  |
> |  9 | nine   |
> | 10 | ten    |
> +----+--------+
> 8 rows in set (0.00 sec)
>
> The physical order of the rows changed (as you can see) but it does not
> re-use the id's that were deleted.
>
> Ordering by the id will get you the last bunch inserted.
>
> If you're using innodb you'll have to be aware it's transaction specific, if
> you're using myisam it will be system wide.

I'll have to check my DBs then, because the exact situation I
described happened to me a few years back when I was first getting
into the DB scene. Regardless, I'm fairly certain the MSSQL box we
have at work behaves this way.


-- 
// Todd

--- End Message ---
--- Begin Message ---

The physical order of the rows changed (as you can see) but it does not
re-use the id's that were deleted.

Ordering by the id will get you the last bunch inserted.

If you're using innodb you'll have to be aware it's transaction specific, if
you're using myisam it will be system wide.

I'll have to check my DBs then, because the exact situation I
described happened to me a few years back when I was first getting
into the DB scene. Regardless, I'm fairly certain the MSSQL box we
have at work behaves this way.

Maybe it's a version thing, that test was done on mysql 5 (I'm sure it'll work on mysql 4.0/4.1 as well). No idea about ones before that.

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


--- End Message ---
--- Begin Message ---
I cannot find anything on google or the manuals/tutorials that gives
some kin of clear explanation of how to so nested selects with where or
whatever.
I have three tables: books, authors and book-authors.
I need to retrieve only those books whose author's names begin with A.
I have tried several maniipulations of where and select with select
subqueries and I cannot get results from the queries.
For example
"SELECT * FROM book b, book_authors c (SELECT id FROM author WHERE
LEFT(author.last_name = $Auth )) as a WHERE a.id = c.authID && b.id =
c.bookID ....<snip>
$Auth = A echoes as A
var_dump returns boolean false
and I get a warning - mysql_num_rows(): supplied argument is not valid....
It is obvious that the syntax is ok, but there is something here that I
do not understand.
It would appear that this should be something very simple, but I don't
see logic working here since I can not do this either
"SELECT * FROM book b, book_authors c, author a WHERE c.authID = (SELECT
a.id WHERE LEFT(a.last_name) = $Auth) && b.id = c.bookID ...
I would really appreciate some help & clarification.
TIA

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- p...@ptahhotep.com
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


--- End Message ---
--- Begin Message ---
PJ wrote:
I cannot find anything on google or the manuals/tutorials that gives
some kin of clear explanation of how to so nested selects with where or
whatever.
I have three tables: books, authors and book-authors.
I need to retrieve only those books whose author's names begin with A.
I have tried several maniipulations of where and select with select
subqueries and I cannot get results from the queries.
For example
"SELECT * FROM book b, book_authors c (SELECT id FROM author WHERE
LEFT(author.last_name = $Auth )) as a WHERE a.id = c.authID && b.id =
c.bookID ....<snip>

Not really a php question :P

You don't need a subquery for this. You can join all of the tables together and just use the where clause to cut down your results, but I'll give an example of both.

select *
from
  books b inner join book_authors c on (b.id=c.bookId)
  inner join authors a on (a.id=c.authorId)
where
  left(a.last_name = 'A');

or

select *
from
  books b inner join book_authors c on (b.id=c.bookId)
where
  c.authorId in (
    select id from authors where left(last_name='A')
  );

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


--- End Message ---
--- Begin Message ---
Chris wrote:
PJ wrote:
I cannot find anything on google or the manuals/tutorials that gives
some kin of clear explanation of how to so nested selects with where or
whatever.
I have three tables: books, authors and book-authors.
I need to retrieve only those books whose author's names begin with A.
I have tried several maniipulations of where and select with select
subqueries and I cannot get results from the queries.
For example
"SELECT * FROM book b, book_authors c (SELECT id FROM author WHERE
LEFT(author.last_name = $Auth )) as a WHERE a.id = c.authID && b.id =
c.bookID ....<snip>

Not really a php question :P

You don't need a subquery for this. You can join all of the tables together and just use the where clause to cut down your results, but I'll give an example of both.

select *
from
  books b inner join book_authors c on (b.id=c.bookId)
  inner join authors a on (a.id=c.authorId)
where
  left(a.last_name = 'A');

correct me if I'm wrong, but did you use the left() function in-correctly?

The documentation shows a different way to use it then you describe.

Something more like the following:

WHERE
   LEFT(a.last_name, 1) = 'A';

But that would be case-sensitive...

So, something like this would work better IMHO

WHERE
   UPPER(LEFT(a.last_name, 1)) = 'A';

or

WHERE
   a.last_name ILIKE 'A%';

would do the trick

or

select *
from
  books b inner join book_authors c on (b.id=c.bookId)
where
  c.authorId in (
    select id from authors where left(last_name='A')

Again...

SELECT id FROM authors WHERE LEFT(last_name, 1) = 'A')

but yet again, case-sensitive...

SELECT id FROM authors WHERE UPPER(LEFT(last_name, 1)) = 'A')
or
SELECT id FROM authors WHERE last_name ILIKE 'A%'

would do the trick

  );




--- End Message ---
--- Begin Message ---
Jim Lucas wrote:
Chris wrote:
PJ wrote:
I cannot find anything on google or the manuals/tutorials that gives
some kin of clear explanation of how to so nested selects with where or
whatever.
I have three tables: books, authors and book-authors.
I need to retrieve only those books whose author's names begin with A.
I have tried several maniipulations of where and select with select
subqueries and I cannot get results from the queries.
For example
"SELECT * FROM book b, book_authors c (SELECT id FROM author WHERE
LEFT(author.last_name = $Auth )) as a WHERE a.id = c.authID && b.id =
c.bookID ....<snip>

Not really a php question :P

You don't need a subquery for this. You can join all of the tables together and just use the where clause to cut down your results, but I'll give an example of both.

select *
from
  books b inner join book_authors c on (b.id=c.bookId)
  inner join authors a on (a.id=c.authorId)
where
  left(a.last_name = 'A');

correct me if I'm wrong, but did you use the left() function in-correctly?

Probably, I didn't look at the doco - I (stupidly I know) assumed it was correct in the original example.

Thanks for the correction.

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


--- End Message ---
--- Begin Message ---
Hello all,

Recently I upgraded a box running phpwiki from php 5.2.8 to 5.2.9. After the upgrade, phpwiki (1.3.14) started spitting out the following two errors, both of which are basically leaving the wiki dead in the water:

[30-Mar-2009 22:01:23] PHP Parse error: syntax error, unexpected T_CLONE, expecting T_STRING in /usr/local/www/data/wikisvn/lib/config.php(500) : eval()'d code on line 2 [30-Mar-2009 22:01:23] PHP Fatal error: Class 'WikiDB_backend_PearDB_PearDB' not found in /usr/local/www/data/wikisvn/lib/WikiDB/SQL.php on line 25

Looking at the changelog, I'm simply not seeing anything that would cause this.

Snippets of both files are below. Looking for any pointers - I need to get the wiki up and running again and phpwiki releases are few and far between.

Thanks,

Charles

first error is in this block:

/**
 * safe php4 definition for clone.
 * php5 copies objects by reference, but we need to clone "deep copy" in
   some places.
 * (BlockParser)
 * We need to eval it as workaround for the php5 parser.
 * See http://www.acko.net/node/54
 */
if (!check_php_version(5)) {
    eval('
    function clone($object) {
      return $object;
    }
    ');
}

And the second error is in here:

 function WikiDB_SQL ($dbparams) {
        $backend = 'PearDB';
        if (is_array($dbparams['dsn']))
            $backend = $dbparams['dsn']['phptype'];
        elseif (preg_match('/^(\w+):/', $dbparams['dsn'], $m))
            $backend = $m[1];
if ($backend == 'postgres7') { // ADODB cross-compatiblity hack (for uni
t testing)
            $backend = 'pgsql';
            if (is_string($dbparams['dsn']))
$dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 10)
;
        }
        include_once ("lib/WikiDB/backend/PearDB_".$backend.".php");
        $backend_class = "WikiDB_backend_PearDB_".$backend;
        $backend = & new $backend_class($dbparams);
        if (DB::isError($backend->_dbh)) return;
        $this->WikiDB($backend, $dbparams);
    }

The variable "$backend" is getting futzed up somewhere...

Not much to go on, I know...



--- End Message ---
--- Begin Message ---
Charles Sprickman wrote:
Hello all,

Recently I upgraded a box running phpwiki from php 5.2.8 to 5.2.9. After the upgrade, phpwiki (1.3.14) started spitting out the following two errors, both of which are basically leaving the wiki dead in the water:

[30-Mar-2009 22:01:23] PHP Parse error: syntax error, unexpected T_CLONE, expecting T_STRING in /usr/local/www/data/wikisvn/lib/config.php(500) : eval()'d code on line 2 [30-Mar-2009 22:01:23] PHP Fatal error: Class 'WikiDB_backend_PearDB_PearDB' not found in /usr/local/www/data/wikisvn/lib/WikiDB/SQL.php on line 25



first error is in this block:

/**
 * safe php4 definition for clone.
 * php5 copies objects by reference, but we need to clone "deep copy" in
   some places.
 * (BlockParser)
 * We need to eval it as workaround for the php5 parser.
 * See http://www.acko.net/node/54
 */
if (!check_php_version(5)) {
    eval('
    function clone($object) {
      return $object;
    }
    ');
}

I know nothing about phpwiki - but it looks like check_php_version() is a function they have defined?

Because reading the code, if check_php_version(5) is support to return true for php 5 then the eval should only be triggered if the version of php is not 5 - in which case, where phpwiki is broken is in the check_php_version() function.

What happens when you run

<?php
if (check_php_version(5)) {
   echo "php 5";
   } else {
   echo "not php 5";
   }
?>

of course you'll need to copy their check_php version() function into your page.
--- End Message ---
--- Begin Message ---
Output buffering turned off?

Bastien

Sent from my iPod

On Mar 30, 2009, at 15:03, Igor Escobar <titiolin...@gmail.com> wrote:

Hi guys, probably everybody goes think: "its the same problem ever" HTML
before header() functions ...  but it is not.

I has working on a project and this are a running in "Windows" (shame on
me).
Recently i migrate to *Ubuntu *and some problems occurred and that
specifically i can't understand WHY this rappening

"Warning: Cannot modify *header* information - headers already sent by"

On my web server on the internet it's OK
On my local web server on my work it's OK
On my loca web server on my notebook it's the problem.

This error occurs only in my notebook (recently that I migrate to linux and
it does not already).

Please, someone have any idea what the fuck is happening?

Regards,
Igor Escobar
systems analyst & interface designer
www . igorescobar . com

--- End Message ---
--- Begin Message ---
Hi there,

I am having trouble to switch with an i18n project to utf-8. The problem is, that php has trouble with files that are saved in UTF-8 with BOM. It is causing strange bahavior like adding extra headers. On the other hand most editors only save UTF-8 with BOM.

Has somebody experienced the same problem? How did you overcome it?

Regards, Merlin

--- End Message ---
--- Begin Message ---
2009/3/31 Merlin Morgenstern <merli...@fastmail.fm>:
> that php has trouble with files that are saved in UTF-8 with BOM. It is
> causing strange bahavior like adding extra headers. On the other hand most
> editors only save UTF-8 with BOM.
>
> Has somebody experienced the same problem? How did you overcome it?
>
Use an Editor that can save without BOM. :-)
I prefer Komodo Edit (Multiplattform) or Notepad++ or gPHPedit if it
should be lightweight.
All mentioned programs are opensource.

Bye

--- End Message ---
--- Begin Message ---
Directly from W3:

http://www.w3.org/International/questions/qa-utf8-bom.en.php

Notepad++ saves without BOM, it's fast, cool, and free ;)

> To: php-gene...@lists.php.net
> Date: Tue, 31 Mar 2009 06:32:41 +0200
> From: merli...@fastmail.fm
> Subject: [PHP] Working in UTF-8 - BOM trouble
> 
> Hi there,
> 
> I am having trouble to switch with an i18n project to utf-8. The problem 
> is, that php has trouble with files that are saved in UTF-8 with BOM. It 
> is causing strange bahavior like adding extra headers. On the other hand 
> most editors only save UTF-8 with BOM.
> 
> Has somebody experienced the same problem? How did you overcome it?
> 
> Regards, Merlin
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx

--- End Message ---
--- Begin Message ---
Hi,

I am interested in this, the problem highlighted also annoyed me. I
haven't  participated in GSoC, nor any community projects  ( i did
want, but didn't had the occasion). I wouldn't mind maintaining this
after GSoc either. Since GSoC is kind of new for me any guidance would
be appreciated.

-- 
Alpar Torok

--- End Message ---
--- Begin Message ---
Hi all,

Another question:

If a script starts to perform an operation and the user browses away will that terminate the thread perfoming the operation eg. the operation is aborted ?

Mvh
Toke

--- End Message ---
--- Begin Message ---
Toke Herkild schrieb:
Hi all,

Another question:

If a script starts to perform an operation and the user browses away will that terminate the thread perfoming the operation eg. the operation is aborted ?

Mvh
Toke
Hi Toke,
i think that the Operations in the Server will not aborted because the Browser was closed. The Browser wait for Response and set a timeout Message when the Time is over.

Best Regards

Carlos Medina

--- End Message ---

Reply via email to