[PHP-DEV] Bug #22651 [Bgs]: mysql_errno/error failing to return a expected error after a failed connect

2003-03-12 Thread Stephen Thorne
Hi all.

This bug was marked as Bogus, but is a real concern for us at ABR, as we may 
use many different databases on different servers in the course of generating 
a page using php.

The long and the short of it is, we can't get an error message if connecting 
to a database fails, after we have already connected to a different database.

Obviously we can't pass the linkID to the second db to mysql_error, becuase on 
a connection failure, linkID is FALSE.

The desired behavior would be that the mysql_error and mysql_errno functions 
would have knowledge of a mysql_connect() failure, and report the error 
returned from the failed mysql_connect() - not to look at errors of the 
currently opened, and therefore default, database.

Regards,
Stephen Thorne.


http://bugs.php.net/?id=22651

 ID:   22651
 User updated by:  craigs at abr dot com dot au
 Reported By:  craigs at abr dot com dot au
 Status:   Bogus
 Bug Type: MySQL related
 Operating System: Redhat Linux Adv Serv 2.1AS
 PHP Version:  4.2.3
 New Comment:

So basically you are saying that even though mysql_error is
now meant to report connect errors (as of 4.0.6), it is not
meant to report connect errors if a link already exists from
a previous connection to a different server?

So now, mysql_error only sometimes returns errors from calls
to the mysql_connect function(since 4.0.6)?


Previous Comments:


[2003-03-11 23:34:32] [EMAIL PROTECTED]

You guess wrong. The default link won't change
if the mysql_connect() fails. (of course not)
And as it's still that $LinkID, and no errors happened
for THAT one, then mysql_error() and mysql_errno() will of course print
nothing.




[2003-03-11 22:52:34] craigs at abr dot com dot au

Calling mysql_errno or mysql_error after a failed
mysql_connect when there is an already existing
mysql connection resource does not return any
error message for the failed connect.

According to the doco, it would be expected to return
an error such as 'Unknown Mysql Server Host'.

I have searched the bug database, and bugs
2051 and 10291 report a related issue of mysql_error/errno
not reporting mysql_connect errors, however a review
of the change log reports support for mysql_connect errors
was added in 4.0.6.

A code segment that reproduces this bug follows

$LinkID = mysql_connect("localhost","login","password");
mysql_select_db("mysql");
mysql_query("SELECT * FROM user");


$LinkID2 = mysql_connect("badserver","login","password");
echo "Mysql Error: ".mysql_errno()." - ".mysql_error()."\n";
==
Expected result- Mysql Error: 2005 - Unknown MySQL Server Host
'badserver' (1)

Actual Result - Mysql Error: 0 -

Commenting out the first 3 lines and re running the script
returns the expected error of unknown server.

I would guess that the mysql_error functions use of a default
link resource of the last open resource is at fault, as none
is opened in the connect.

Cheers
Craig



---


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] iterating objects with interfaces

2003-03-11 Thread Stephen Thorne
All this is starting to feel strangely pythonic.

How soon till 
(''.($_GET['textArea']->strip_tags()).'')->print(); ?

Stephen.

On Wed, 12 Mar 2003 10:24, Marcus Börger wrote:
> At 19:05 10.03.2003, Marcus Börger wrote:
> >Standard PHP Library
>
> Updated version allows:
>
> class obj_array implements spl::array_read {
> bla ...
> }
>
> $obj = new obj_array();
>
> $value = $obj[$index];
>
> marcus


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



Re: [PHP-DEV] session_set_save_handler and session_start

2003-02-09 Thread Stephen Thorne
Just a thought - have you tried passing $hnd by reference?

array(&$hnd, "open_session")

Otherwise when you try and set state in the class for it to be accessed 
elsewhere, it won't work because you've got (in this case) 6 distinct copies 
of the class used in handlers, and presumably a 7th (the original) that 
you're using in your code.

Regards,
Stephen Thorne.

On Mon, 10 Feb 2003 06:42, michel 'ziobudda' morelli wrote:
> Hi, I'm tryng new possibility to set a session handler via class:
>
> session_set_save_handler(array($hnd, "open_session"),
>array($hnd, "close_session"),
>array($hnd, "read_session"),
>array($hnd, "write_session"),
>array($hnd, "destroy_session"),
>array($hnd, "gc_session")
>
>
> Now, I'm using this read_session (into class):
>
> function read_session($sessionid)
> {
> $query = "select value,last from session where id =
> '".session_id()."'";
> $this->dbms->Exec_Query($query);
>   //think the result like 'id|i:0;'
> if ($this->dbms->ReturnNum() == 0) {
> $session_exist = false;
> } else {
>   zb_debug("session exist");
>   $session_exist = true;
>   $session = $this->dbms->ReturnNextObject();
>   zb_debug("value of session is ".$session->value);
>
>   $expire = session_cache_expire();
>   if ( ($session->last + $expire) < time() ) {
>   zb_debug("Session expire");
>   zb_debug("delete from DB");
>   $query = "delete from session where id =
> '".session_id()."'";
>   $this->dbms->Exec_Query($query);
>   zb_debug("session deleted");
>   //La sessione è scaduta.
>   $this->session_exist = false;
>   } else {
> session_decode($session->value);
> var_dump($_SESSION);
>
>   /**
>this is the result: array(0) { }
>ERROR!
>   */
>
> }
>
>   }
>
> return true;
> }
>
> Why the session_decode give me an empty array ??
>
> I'm tring
>   session_start()
>   session_set...
> but the result is that my handler is ignored
>
> so I'm tring
>   session_set...
>   session_start()
> but the result is an empty _SESSION array.
>
> Where is my error ?
>
> I have see the possibility to make a session-handler vie class into
> tests directory so I have thinked that this is a php5 problem (or a my
> problem with php5).
>
> Using cvs via
>
> cvs -z3 -d :pserver:[EMAIL PROTECTED]:/repository -z3 co php5
>
> and with this configure:
>
> ./configure --with-apxs2=/usr/local/httpd-2.0.43/bin/apxs
> --prefix=/usr/local/php5-`date +%d%m%G`/ -
> -with-openssl --with-zlib --with-bz2 --with-gd --with-mysql
> --with-xmlrpc
>
> Tnx in advance for all.


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version of str_replace()

2003-01-29 Thread Stephen Thorne
On Thu, 30 Jan 2003 09:09, Ilia A. wrote:
> On January 29, 2003 04:35 pm, Shane Caraveo wrote:
> > What's the benchmark code?  How is the benchmark difference on large
> > text (ie. 100K of text) vs. small text (1K or smaller)?
>
> Attached is the benchmark script that I've used. I've intentionally used
> 'small' strings, since that is what I imagine is most common usage of the
> function.
>
> Ilia

Large html files might be another good test. As I've often seen crude template 
created with str_replace.

I'm having fun actually getting round to investigating this. I've always just 
believed what the manual says "if you don't need the power of regex, use 
str_replace instead".

I wonder if we should include ereg in our benchmarks too..

Regards
Stephen Thorne.

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version of str_replace()

2003-01-29 Thread Stephen Thorne
Gah.

I botched that, I didn't reset the timer.

Total Time: 00:00:03.08 //str_replace
Total Time: 00:00:04.32 //preg_replace
Total Time: 00:00:03.05 //str_replace
Total Time: 00:00:03.67 //preg_replace
Total Time: 00:00:03.27 //str_replace
Total Time: 00:00:04.40 //preg_replace

Closer than I thought. Probably deserves a better comparison tho. From these 
results I'll probably stop yelling at people for using preg_replace when 
str_replace will do.

Regards
Stephen Thorne.

On Thu, 30 Jan 2003 08:50, Stephen Thorne wrote:
> On Thu, 30 Jan 2003 06:48, Ilia A. wrote:
> > > I may be wrong since I haven't profiled this, but my understanding is
> > > that str_replace is much faster than doing either of the regex
> > > replacements.  For that reason alone, there is a use for it.
> >
> > Normally it would be quite faster, however once case sensitivity is added
> > to the mix I believe the speed difference would be minimal. I've done
> > some benchmarks and the speed difference between str_replace() and
> > preg_replace() is only about 1/2 second in across 10 executions (5
> > replaces per instance). Another .6 of a second is added when
> > preg_replace() is used with 'i' flag which makes it case insensitive. I
> > have not benchmarked the stri_replace code but I imagine it would be in
> > the same ballpark, meaning that we are adding a fairly large chunk of
> > code for performance benefit of a 1 microsecond (1 millionth of a second)
> > per instance.
> >
> > Ilia
>
> Lies, damn lies and statistics.
>
> You say the difference is only 1/2 second accross 10 executions, but
> that means nothing unless you put it in context of how long the 10
> executions took. 1/2 second could mean 90% difference or 1% differene.
>
> I wrote a very unscientific script to do a simple benchmark
>
>  include('stopwatch.inc');
> $SW = new StopWatch;
> for ($i=0;$i<50;$i++)
> str_replace('abcdefgh', 'def',
> 'fkjdals;fjdsakl;fjdsakl;fjdskl;fadabcdefghfdsafdsafdsa');
> $SW->Stop();
>
> for ($i=0;$i<50;$i++)
> preg_replace('/abcdefgh/', 'def',
> 'fkjdals;fjdsakl;fjdsakl;fjdskl;fadabcdefghfdsafdsafdsa');
> $SW->Stop();
> ?>
>
> I did quite a few runs and picked the upper and lower end of the results to
> paste here
>
> Biggest difference
> Total Time: 00:00:03.00
> Total Time: 00:00:08.90
>
> Smallest difference
> Total Time: 00:00:03.12
> Total Time: 00:00:06.94
>
> Bearing in mind this is on a pre-working-hours quad hyperthreaded 1.4ghz
> xeon box. So I've got a cpu just about all to myself here.
>
> Regards,
> Stephen Thorne.


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP-DEV] Feature Request #5919 case-insensitive version of str_replace()

2003-01-29 Thread Stephen Thorne
On Thu, 30 Jan 2003 06:48, Ilia A. wrote:
> > I may be wrong since I haven't profiled this, but my understanding is
> > that str_replace is much faster than doing either of the regex
> > replacements.  For that reason alone, there is a use for it.
>
> Normally it would be quite faster, however once case sensitivity is added
> to the mix I believe the speed difference would be minimal. I've done some
> benchmarks and the speed difference between str_replace() and
> preg_replace() is only about 1/2 second in across 10 executions (5
> replaces per instance). Another .6 of a second is added when preg_replace()
> is used with 'i' flag which makes it case insensitive. I have not
> benchmarked the stri_replace code but I imagine it would be in the same
> ballpark, meaning that we are adding a fairly large chunk of code for
> performance benefit of a 1 microsecond (1 millionth of a second) per
> instance.
>
> Ilia

Lies, damn lies and statistics.

You say the difference is only 1/2 second accross 10 executions, but that 
means nothing unless you put it in context of how long the 10 executions 
took. 1/2 second could mean 90% difference or 1% differene.

I wrote a very unscientific script to do a simple benchmark

Stop();

for ($i=0;$i<50;$i++)
preg_replace('/abcdefgh/', 'def', 
'fkjdals;fjdsakl;fjdsakl;fjdskl;fadabcdefghfdsafdsafdsa');
$SW->Stop();
?>

I did quite a few runs and picked the upper and lower end of the results to 
paste here 

Biggest difference
Total Time: 00:00:03.00
Total Time: 00:00:08.90

Smallest difference
Total Time: 00:00:03.12
Total Time: 00:00:06.94

Bearing in mind this is on a pre-working-hours quad hyperthreaded 1.4ghz xeon 
box. So I've got a cpu just about all to myself here.

Regards,
Stephen Thorne.

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php