473,491 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Suggestion for porting function to PHP5??

Hello, I was hoping someone could provide some insight as to the best
approach to take in porting over a function I use in quite a few spots
from PHP4 to PHP5. Basically, I have a db wrapper class that I use
called DBConn (this is the PHP5 ported definition for the members, PHP4
was the same except "private" was "var"):

class DBConn
{
private $hDB; //db link
private $bConnected; //db link status
private $bInTX; //current transaction status, used to avoid
deadlocks
private $hResult; //result link
private $iNumResultRows;
}

with those being the members. Within this class, I also have the
following method (this is the PHP4 definition for the method):

function doEscapeString($a_stInputString)
{
if (isset($this->hDB)) {
return mysql_real_escape_string($a_stInputString, $this->hDB);
}

$l_stServer = 'localhost';
$l_stUsername = 'escape_tester';
$l_stPassword = 'a1b2c3d4';

$l_hDBForFunc =
mysql_connect($l_stServer,$l_stUsername,$l_stPassw ord,FALSE,2);
return mysql_real_escape_string($a_stInputString, $l_hDBForFunc);
}

"escape_tester" is a completely unprivileged account, used only for the
escape_string function connection when necessary. As you can see, in
PHP4, since it doesn't do such strict checking, you are allowed to
check for the existence of the "$this" variable prior to creating the
new connection, even when you call the method statically via
DBConn::doEscapeString. Obviously, this has changed in PHP5 thanks to
the new object implementation, and "$this" never exists for a static
public function (as you have to change doEscapeString to in order to
not cause an error when calling it statically in your code). Here is
the PHP5 version:

public static function doEscapeString($a_stInputString)
{
$l_stServer = 'localhost';
$l_stUsername = 'escape_tester';
$l_stPassword = 'a1b2c3d4';

$l_hDBForFunc =
mysqli_connect($l_stServer,$l_stUsername,$l_stPass word);
return mysqli_real_escape_string($l_hDBForFunc,$a_stInput String);
}

What I'm trying to d is figure out a way that I can still have a test
for the existence of a current db link prior to ALWAYS creating a new
connection for each call to doEscapeString. There are quite a few spots
in my code where a "$l_roDBConn = new DBConn" was created prior to ever
calling "doEscapeString". In those cases, I would later use
"$l_roDBConn->doEscapeString(xxx)" instead of calling it statically...
thus reusing the existing connection. This no longer is possible with
PHP5 though unfortunately. Any suggestions as to what could be done to
regain the old PHP4 functionality? Thanks in advance for any and all
replies.

Tim

Aug 23 '06 #1
0 1198

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

Similar topics

2
1614
by: Andrea A | last post by:
Hi all, I'm starting implementig a big website in PHP and i will finish it by the end of August. What recommendations do you have about implementing in php5 ? And where can I found more...
1
2185
by: Arne Claus | last post by:
Hi. I've got a strange problem here with PHP5 (5.0.4). I've got file A, defining a class A and a file B, which sets up an Object of A (aObj) in the global scope like this. ----- A.php ----...
4
2356
by: Chris Travers | last post by:
Hi all; A few years ago, I set about porting a PHP application from MySQL to PostgreSQL, after realizing that MySQL wasn't going to be able to handle it. In order to do this, I built a light,...
5
2767
by: awdsites | last post by:
Hi, I'm a noob with a server so keep that in mind :) Been trying to connect with php to mysql and all I get is: "Fatal error: Call to undefined function: mysql_connect()" I've read and read...
4
1483
by: Jon | last post by:
function query($query, $return = false) { $fetch = mysql_query($query, $this->connection) or die2(mysql_error($this->connection)); if($return) return $fetch; } mysql_error(): supplied...
14
2360
by: Manish | last post by:
The project I am developing doesn't involves database. I want to parse the mailbox file (.mbx) and store the summary in the text file for fast retrieval and display of information in the Inbox...
4
2593
by: Bit Byte | last post by:
Noobie here (C++/C/Java experience though) ... Recently picked up PHP ... I want to pass an array to a function and then to use count on the passed variable - is this the way to do it (its an...
9
5239
by: java | last post by:
Hey there, I just removed an elderly PHP4-Installation from my Windows-Box and installed PHP 5.2.1. I used the PHP4-Module as local batchfile- interpreter by E:\ersDHCP>php ./extractLog.php ...
0
1380
by: Erwin Moller | last post by:
Hi group, I found something strange in PHP5.2.4 (on IIS7/Vista). I am working on an app that has been running just fine under heavy load for over a year at some custumer of mine. (they have...
0
6980
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7157
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,...
0
7192
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6862
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
7364
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
5452
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
4886
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
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
637
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.