473,503 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extending the mysqli class

Daz
Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.

Feb 25 '07 #1
21 7238
Daz wrote:
Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.
Daz,

If you're going to extend a class, you don't use:

$this->connection = new mysqli($server, $username,
$password, $database);

You already have an instance of mysqli via inheritance; this would be
creating another one.

Rather, you should be using

parent::mysqli($server, $username, $password, $database);

(Assuming PHP4 from your previous post).

You also don't need to keep the $connection - mysqli will maintain that
info..

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #2
Daz
On Feb 25, 3:41 pm, "Daz" <cutenfu...@gmail.comwrote:
Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.

OK, I've done some more thinking, and I think that what I am trying to
do, would involve overriding the constructor of the mysqli class,
which I guess wouldn't be wise, and might not even be possible.

Is there any way to override the contructor and find out what the
constructor code is? I guess that it wouldn't be a PHP class as such,
but more of a hybrid, but I am uncertain.

I can see that what I am doing is correct for adding extra functions,
but I would appreciate it if anyone can help me figure out the best
way to do some error checking when the connection is opened.

I would also appreciate any input on overriding the default methods,
i.e whether it's possible or not, or whether it's ill advised, or if I
can actually use the original constructor and carefully modify it.

I think the initial error checking might require an external function
which instantiates the class, and does the checking, then returns the
mysqli object if all went well, or returns false if it didn't.

Feb 25 '07 #3
Daz
On Feb 25, 3:55 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Daz wrote:
Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:
<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>
All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.
At the present time, this works:
$db =& new sql_db("myUsername", "myPass", "someDB");
But as soon as I try to query a table, like so:
$res = $db->query("SELECT * FROM `some_table`;");
I get:
Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21
Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.
Thanks in advance.
Daz.

Daz,

If you're going to extend a class, you don't use:

$this->connection = new mysqli($server, $username,
$password, $database);

You already have an instance of mysqli via inheritance; this would be
creating another one.

Rather, you should be using

parent::mysqli($server, $username, $password, $database);

(Assuming PHP4 from your previous post).

You also don't need to keep the $connection - mysqli will maintain that
info..

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thanks for that Jerry. That gives me something to go on. I am using
PHP5, as I believe PHP4 doesn't support the mysqli object (but I am
most likely wrong).

Thanks again for your assistance.

Daz.

Feb 25 '07 #4
Daz wrote:
On Feb 25, 3:55 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Daz wrote:
>>Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:
<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>
All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.
At the present time, this works:
$db =& new sql_db("myUsername", "myPass", "someDB");
But as soon as I try to query a table, like so:
$res = $db->query("SELECT * FROM `some_table`;");
I get:
Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21
Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.
Thanks in advance.
Daz.
Daz,

If you're going to extend a class, you don't use:

$this->connection = new mysqli($server, $username,
$password, $database);

You already have an instance of mysqli via inheritance; this would be
creating another one.

Rather, you should be using

parent::mysqli($server, $username, $password, $database);

(Assuming PHP4 from your previous post).

You also don't need to keep the $connection - mysqli will maintain that
info..

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================


Thanks for that Jerry. That gives me something to go on. I am using
PHP5, as I believe PHP4 doesn't support the mysqli object (but I am
most likely wrong).

Thanks again for your assistance.

Daz.
Daz,

Actually, PHP4 does support the mysqli object, also.

But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)

instead.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #5
Daz wrote:
On Feb 25, 3:41 pm, "Daz" <cutenfu...@gmail.comwrote:
>Hi everyone.

I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:

<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>

All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.

At the present time, this works:

$db =& new sql_db("myUsername", "myPass", "someDB");

But as soon as I try to query a table, like so:

$res = $db->query("SELECT * FROM `some_table`;");

I get:

Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21

Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.

Thanks in advance.

Daz.


OK, I've done some more thinking, and I think that what I am trying to
do, would involve overriding the constructor of the mysqli class,
which I guess wouldn't be wise, and might not even be possible.

Is there any way to override the contructor and find out what the
constructor code is? I guess that it wouldn't be a PHP class as such,
but more of a hybrid, but I am uncertain.

I can see that what I am doing is correct for adding extra functions,
but I would appreciate it if anyone can help me figure out the best
way to do some error checking when the connection is opened.

I would also appreciate any input on overriding the default methods,
i.e whether it's possible or not, or whether it's ill advised, or if I
can actually use the original constructor and carefully modify it.

I think the initial error checking might require an external function
which instantiates the class, and does the checking, then returns the
mysqli object if all went well, or returns false if it didn't.
Daz,

Overriding the constructor is quite common. But you need to ensure you
also call the parent class constructor.

As to seeing the code - it's like anything else in PHP. If it's a PHP
file, you can see the code. If, like with mysqli, it's a compiled
extension, you need to look at the source code for the extension.

If you want some error checking when you open the connection, see if the
connection is open after calling the mysqli constructor (see if
mysqli_connect_error() is non-zero).

You don't need an external function - you just need to check for errors.
And if you don't want to keep checking the responses, check you
exception handling.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #6
Daz
On Feb 25, 4:17 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Daz wrote:
On Feb 25, 3:41 pm, "Daz" <cutenfu...@gmail.comwrote:
Hi everyone.
I am trying to create an extension of the mysqli class within PHP, and
I am finding it quite difficult. I am fairly new to PHP classes, and
decided to give them a go. Here's what I have to far:
<?php
class sql_db extends mysqli
{
var $connection = false;
function sql_db($username, $password, $database="",
$server="localhost")
{
$this->connection = new mysqli($server, $username,
$password, $database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n",
mysqli_connect_error());
exit();
}
return = $this->connection;
}
}
?>
All I am trying to achieve for now is for a simple error to be printed
if the connection to the database fails. Rather than have error
checking for each within each PHP file, I would just like to have it
all done systematically. I would also like to add a few of my own
methods, such as having the object pass back a PHP array, rather than
a MySQL array. I know I can do this with a separate function, but
really I am doing this for the learning experience more than anything.
At the present time, this works:
$db =& new sql_db("myUsername", "myPass", "someDB");
But as soon as I try to query a table, like so:
$res = $db->query("SELECT * FROM `some_table`;");
I get:
Warning: mysqli::query(): Couldn't fetch sql_db in - on line 21
Evidently I am doing something wrong, and I would really appreciate
any pointers. I suspect that I can't actually do what I want to do,
although I can't see why not. In any case, I am sure it's possible,
but I am going about it completely wrong.
Thanks in advance.
Daz.
OK, I've done some more thinking, and I think that what I am trying to
do, would involve overriding the constructor of the mysqli class,
which I guess wouldn't be wise, and might not even be possible.
Is there any way to override the contructor and find out what the
constructor code is? I guess that it wouldn't be a PHP class as such,
but more of a hybrid, but I am uncertain.
I can see that what I am doing is correct for adding extra functions,
but I would appreciate it if anyone can help me figure out the best
way to do some error checking when the connection is opened.
I would also appreciate any input on overriding the default methods,
i.e whether it's possible or not, or whether it's ill advised, or if I
can actually use the original constructor and carefully modify it.
I think the initial error checking might require an external function
which instantiates the class, and does the checking, then returns the
mysqli object if all went well, or returns false if it didn't.

Daz,

Overriding the constructor is quite common. But you need to ensure you
also call the parent class constructor.

As to seeing the code - it's like anything else in PHP. If it's a PHP
file, you can see the code. If, like with mysqli, it's a compiled
extension, you need to look at the source code for the extension.

If you want some error checking when you open the connection, see if the
connection is open after calling the mysqli constructor (see if
mysqli_connect_error() is non-zero).

You don't need an external function - you just need to check for errors.
And if you don't want to keep checking the responses, check you
exception handling.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Thanks for that Jerry. You're a star! :)

Feb 25 '07 #7
Actually, PHP4 does support the mysqli object, also.

But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)
Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}
}

output_methods("mysqli");
?>

Feb 25 '07 #8
Actually, PHP4 does support the mysqli object, also.
>
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)
Also just thought of another clarification. If you do not declare a
constructor for a class that extends another class, the parent constructor
will be called. for example the following code snippet will output "parent
constructor and the input was THIS TEXT":-

<?php
class c1
{
function __construct($input)
{
echo "parent constructor and the input was ".$input;
}
}
class c2 extends c1
{
}
$c = new c2('THIS TEXT');
?>
Feb 25 '07 #9
Daz
On Feb 25, 5:15 pm, "peter" <sub...@flexiwebhost.comwrote:
Actually, PHP4 does support the mysqli object, also.
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call
parent::construct(...)

Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}

}

output_methods("mysqli");
?>

Excellent! Just what I needed :)

I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique, as there's no guarantee that the server it needs to run on
is running PHP5. Some people have no control over what version of PHP
is installed if they are simply paying for a basic hosting account.
Fortunately for me, I have the choice between 4 and 5, but others
won't necessarilly be quite so fortunate.

Thanks for your help Peter. That's sure going to save me digging
through source code and scratching my head to to point of baldness.

Best wishes.

Daz.

Feb 25 '07 #10
Daz
On Feb 25, 5:15 pm, "peter" <sub...@flexiwebhost.comwrote:
Actually, PHP4 does support the mysqli object, also.
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call
parent::construct(...)

Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}

}

output_methods("mysqli");
?>

I have just one more question. Seeing that you can print methods, how
would I print the code from a function?

Many thanks.

Daz.

Feb 25 '07 #11
peter wrote:
>Actually, PHP4 does support the mysqli object, also.

But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call

parent::construct(...)

Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.
That's true if there is no __constructor method. However, from what I
understand, the old classname constructor is going away. If you're on
PHP5, you should be using the new way.
The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}
}

output_methods("mysqli");
?>

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #12
Daz wrote:
On Feb 25, 5:15 pm, "peter" <sub...@flexiwebhost.comwrote:
>>Actually, PHP4 does support the mysqli object, also.
But in PHP5 your constructors are named __construct, not the class name.
So you need to change the constructor name in your class, and call
parent::construct(...)
Just a correction of Jerry's post. As of php 5 the __constructor method was
made available BUT the old constructor name is still useable.

The class you are actually using (mysqli) does in fact use a contructor
called mysqli as the following code snippet will demonstrate if you run it:-

<?php
function output_methods($obj)
{
$methods = get_class_methods($obj);
foreach ($methods as $method)
{
echo "function $method()\n";
}

}

output_methods("mysqli");
?>


Excellent! Just what I needed :)

I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique, as there's no guarantee that the server it needs to run on
is running PHP5. Some people have no control over what version of PHP
is installed if they are simply paying for a basic hosting account.
Fortunately for me, I have the choice between 4 and 5, but others
won't necessarilly be quite so fortunate.

Thanks for your help Peter. That's sure going to save me digging
through source code and scratching my head to to point of baldness.

Best wishes.

Daz.
Daz,

It was changed because they're moving away from the old classname
constructor to just __constructor. New code on php5 should be using the
new method.

For compatibility with PHP4, just create your constructor as
__constructor. Then create a classname constructor and have it call
__constructor.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 25 '07 #13
..oO(Daz)
>I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique
I don't care about PHP 4 anymore. Personally I consider it dead.
>as there's no guarantee that the server it needs to run on
is running PHP5.
My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.

Micha
Feb 25 '07 #14
I havejustone more question. Seeing that you can print methods, how
would I print the code from a function?
As far as I know you cannot print the code for a class method only
retrieve it's name.

(had to use google groups to post a reply as for some some reason my
news provider is not working properly)

Feb 25 '07 #15
I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, wouldjustuse the PHP4 constructor
technique

I don't care aboutPHP4 anymore. Personally I consider it dead.
as there's no guarantee that the server it needs to run on
is running PHP5.

My scripts make use of many of the new OOP features inPHP5, so they
won't run at all onPHP4.

Micha
That is all good and well if you are only coding for yourself but as
the following stats page shows php 4 still has 85% or the market
(although it is decreasing at an ever faster rate)

http://www.nexen.net/chiffres_cles/p...olution.global

Feb 25 '07 #16
..oO(ad***@fahost.com)
>My scripts make use of many of the new OOP features inPHP5, so they
won't run at all onPHP4.

That is all good and well if you are only coding for yourself but as
the following stats page shows php 4 still has 85% or the market
(although it is decreasing at an ever faster rate)
I'm not only coding for myself, but I clearly state that my scripts
require a PHP 5 server and usually I'm the one who decides where to host
a site.

Similarly you can't expect modern software to run on an old system like
Windows 3.1 anymore. And PHP 4 _is_ old. At some point you simply have
to draw the line.

Micha
Feb 26 '07 #17
Michael Fesser wrote:
.oO(Daz)
>I am wondering why constructors are different in PHP5. Surely anyone
coding portable scripts, would just use the PHP4 constructor
technique

I don't care about PHP 4 anymore. Personally I consider it dead.
>as there's no guarantee that the server it needs to run on
is running PHP5.

My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.

Micha
Micha,

Maybe you consider it dead. But there are probably hundreds of
thousands of shared ISP's out there who disagree with you. And PHP 4 is
not past end-of-life yet, according to PHP.NET.

A good consultant takes all this into consideration, also.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 26 '07 #18
..oO(Jerry Stuckle)
>Michael Fesser wrote:
>>
My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.
Maybe you consider it dead. But there are probably hundreds of
thousands of shared ISP's out there who disagree with you.
Sure, but I don't write my scripts for such servers.

I don't know about the situation where you are, but at least here in
Germany offering PHP 5 support is a _must_ for a reputable host.
>And PHP 4 is
not past end-of-life yet, according to PHP.NET.
PHP 6 is going to see the light of day.
>A good consultant takes all this into consideration, also.
A good consultant also knows when it's time for an important upgrade or
a host change. PHP 5 not only has much more features than PHP 4, but is
also faster, more secure and more flexible.

Micha
Feb 26 '07 #19
Michael Fesser wrote:
.oO(Jerry Stuckle)
>Michael Fesser wrote:
>>My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.
Maybe you consider it dead. But there are probably hundreds of
thousands of shared ISP's out there who disagree with you.

Sure, but I don't write my scripts for such servers.

I don't know about the situation where you are, but at least here in
Germany offering PHP 5 support is a _must_ for a reputable host.
>And PHP 4 is
not past end-of-life yet, according to PHP.NET.

PHP 6 is going to see the light of day.
>A good consultant takes all this into consideration, also.

A good consultant also knows when it's time for an important upgrade or
a host change. PHP 5 not only has much more features than PHP 4, but is
also faster, more secure and more flexible.

Micha
Micha,

No arguments about it being faster, etc. However, the market doesn't
always upgrade to the latest. There are a lot of hosts still running
PHP4, all over the world. And to say you won't program for them means
you're missing an awful lot of customers.

But hey - it's your loss, not mine.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Feb 26 '07 #20
Daz wrote:
I am wondering why constructors are different in PHP5.
Under PHP 4:

<?php
class A
{
function A ()
{
print "Constructor called\n";
}
}

class B extends A
{
// The constructor for this class is now a
// function called 'A'. If you were reading the
// code, this might be somewhat confusing, but
// you could logically infer that it's because
// it extends A.
}

class C extends B
{
// The constructor for this class is now a
// function called 'A'. There is no clue within
// this class definition as to why that is! If
// classes A and B were defined in a separate
// file, then there would be no clues in this
// file that the constructor function is called
// 'A'.
}

class D extends C
{
function D ()
{
print "This is D!\n";
parent::C(); // wrong!
}
}
?>

PHP 5 allows all classes to have the same name for their constructor. So
when subclassing an existing class, you can reliably call the parent's
constructor function as "parent::__contruct()" without having to look into
the internals of the class that you're extending. (Which is how it should
be with OO programming: classes should be black boxes.)

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 27 '07 #21
Michael Fesser wrote:
My scripts make use of many of the new OOP features in PHP 5, so they
won't run at all on PHP 4.
Ditto.

My current big pet project is http://demiblog.org/. This is PHP 5+ only
and supports MySQL 5+ and PostgreSQL 8+. Although I do realise that earlier
versions of these packages are still quite widely used out there, this
project probably won't hit the big 1.0 for another year or two, by which
time, the hosting world will have probably moved on a lot. Supporting
older versions of PHP and the database engines will cost development time
and push back the project release date even later, by which time PHP 4
support will be even less relevant.

So although PHP 4 may still be alive right now, it's counting down the
days to his retirement when it can hand over the family business to his
son PHP 5. He's heard the happy news that his dranddaughter PHP 6 is
planning on following in their footsteps too as soon as she graduates.
Because of PHP 4's impending retirements, he's not taking on any more big
projects at work, and is letting his son take on most of the new clients.

Analogy over, it would be unwise at this point to look at supporting PHP 4
for any medium-to-large projects that are starting now or in the future.
Existing PHP 4 projects should probably keep supporting PHP 4 for a while
yet, but should certainly make an effort to support PHP 5 as well, and
should be keeping a close eye on PHP 6 developments.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Feb 27 '07 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2046
by: Hayden Kirk | last post by:
Can anyone tell me out to make a new mysqli class. Im going $var = new mysql(); I get an error unknown class, php 5.0.3 Thanks
1
3791
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
12
4719
by: davids58 | last post by:
trying to figure out how to use a mysql database with PHP. I ran the following code: <?php // defines database connection data define('DB_HOST', 'localhost'); define('DB_USER', 'ajaxuser');...
2
2745
by: Curtis | last post by:
Hello everyone: Recently, I decided to upgrade to PHP 5.2.0. I have C:\php5 in the Windows XP PATH, so upgrading is quite painless; just unzip new release, and restart Apache! Usually it goes...
13
3687
by: Schmidty | last post by:
If you do a page reload with $_SERVER will your program lose a mysqli connection upon the reload of the page? Would this code work? I need to know how to carry over a connection between methods as...
2
2593
by: Curtis | last post by:
Hello everyone: I have come to love the ease of updating PHP, since getting used to using it these past few years. Recently, however, when I upgraded from PHP 5.1 to PHP 5.2.0 and again when...
11
11063
by: macca | last post by:
Hi, What should I be using for general MySQL database access? I've been using the traditional mysql extension for ages, but I'm trying to update my style to a more OOP paradigm. I've used...
2
3190
by: Michael | last post by:
Hi, I try to use mysqli object instead of standard mysql functions. Is it ok to create mysqli object within my class or schould I pass mysqli object to my object. The problem is, with code...
3
2296
code green
by: code green | last post by:
I am still using the mysql extension rather than the mysqli. Moving to mysqli would be realively simple in my case because all mysql_ procedural calls are wrapped in a class MySqlDB(). As are...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.