By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

mysqli connections and oop

P: n/a
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...

Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();

if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser

class newuser {
public $name;
private $passwd;
private $mysqli;

function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor

function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if

} // end function

function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";

} // end function

} //end class

Jan 24 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Schmidty wrote:
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...

Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();

if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser

class newuser {
public $name;
private $passwd;
private $mysqli;

function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor

function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if

} // end function

function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";

} // end function

} //end class
Schmidty,

As I explained in comp.database.mysql, you can't. Once a page's
processing is completed, all connections (and objects) are released.

You can keep information like user ids, etc. in the $_SESSION variable,
but not the connection. Even if you could keep the connection info in
there, the connection itself will be closed.

Each page is it's own little program. Any external resources opened by
it are closed at the end of the page processing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 24 '07 #2

P: n/a
So if I do a $_SERVER['PHP_SELF'] in a function within a class that
will end the execution of that class and restart the same script? Do I
need to do all processing in a script before I display a page that will
have a $_SERVER['PHP_SELF'] action? Thanks for the help...

Schmidty

On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidty wrote:
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...
Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();
if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser
class newuser {
public $name;
private $passwd;
private $mysqli;
function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor
function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";
} // end function
} //end classSchmidty,

As I explained in comp.database.mysql, you can't. Once a page's
processing is completed, all connections (and objects) are released.

You can keep information like user ids, etc. in the $_SESSION variable,
but not the connection. Even if you could keep the connection info in
there, the connection itself will be closed.

Each page is it's own little program. Any external resources opened by
it are closed at the end of the page processing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Jan 24 '07 #3

P: n/a
Schmidty wrote:
So if I do a $_SERVER['PHP_SELF'] in a function within a class that
will end the execution of that class and restart the same script? Do I
need to do all processing in a script before I display a page that will
have a $_SERVER['PHP_SELF'] action? Thanks for the help...

Schmidty
Hi,

Please don't toppost. It destroys the order of the conversation.
$_SERVER['PHP_SELF'] is just a string that contains the script that is being
executed.
I do not understand what 'doing a $_SERVER['PHP_SELF'] in a function' means.
But it will most probably NOT terminated the execution of the script.
exit(); does.

You must clearly see the difference between the server and the client
(browser).

Your script produces a form that will be send back to the client (=browser).
Then your script ends.
The form action in your example posts back to the same script (because you
used the target for the action $_SERVER['PHP_SELF']), so if anybody presses
submit, that form will be posted, and hence the same script will be
executed as before.
But the server or PHP couldn't care less, and thinks of it as just another
call to that script.

http-protocol is stateless, this means that NO lasting connection is build
between the client and the server. To overcome this you must use sessions.

And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script ends.
So you'll have to rebuild your connection each invocation of a script that
needs a database.

Hope this helps.

Regards,
Erwin Moller

>
On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Schmidty wrote:
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...
Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();
if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser
class newuser {
public $name;
private $passwd;
private $mysqli;
function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor
function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";
} // end function
} //end classSchmidty,

As I explained in comp.database.mysql, you can't. Once a page's
processing is completed, all connections (and objects) are released.

You can keep information like user ids, etc. in the $_SESSION variable,
but not the connection. Even if you could keep the connection info in
there, the connection itself will be closed.

Each page is it's own little program. Any external resources opened by
it are closed at the end of the page processing.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Jan 24 '07 #4

P: n/a


On Jan 24, 1:26 am, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Schmidty wrote:
So if I do a $_SERVER['PHP_SELF'] in a function within a class that
will end the execution of that class and restart the same script? Do I
need to do all processing in a script before I display a page that will
have a $_SERVER['PHP_SELF'] action? Thanks for the help...
SchmidtyHi,

Please don't toppost. It destroys the order of the conversation.
$_SERVER['PHP_SELF'] is just a string that contains the script that is being
executed.
I do not understand what 'doing a $_SERVER['PHP_SELF'] in a function' means.
But it will most probably NOT terminated the execution of the script.
exit(); does.

You must clearly see the difference between the server and the client
(browser).

Your script produces a form that will be send back to the client (=browser).
Then your script ends.
The form action in your example posts back to the same script (because you
used the target for the action $_SERVER['PHP_SELF']), so if anybody presses
submit, that form will be posted, and hence the same script will be
executed as before.
But the server or PHP couldn't care less, and thinks of it as just another
call to that script.

http-protocol is stateless, this means that NO lasting connection is build
between the client and the server. To overcome this you must use sessions.

And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script ends.
So you'll have to rebuild your connection each invocation of a script that
needs a database.

Hope this helps.

Regards,
Erwin Moller


On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidty wrote:
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...
Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();
if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser
class newuser {
public $name;
private $passwd;
private $mysqli;
function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor
function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";
} // end function
} //end classSchmidty,
As I explained in comp.database.mysql, you can't. Once a page's
processing is completed, all connections (and objects) are released.
You can keep information like user ids, etc. in the $_SESSION variable,
but not the connection. Even if you could keep the connection info in
there, the connection itself will be closed.
Each page is it's own little program. Any external resources opened by
it are closed at the end of the page processing.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -- Show quoted text -
Thanks Erwin

The Google Groups editor places your reponse at the top when making a
reply. I went ahead posted at the bottom for you...

I understand that HTTP is stateless and I have been using sessions
variables and understand that you can't carry a database connection
through either one. I was confused on what happens with an
$_SERVER['HTTP_SELF'] in a script. What I meant by "doing a
$_SERVER['PHP_SELF'] in a function" is having a page echoed in a
function and having the 'action' of that page execute a
$_SERVER['HTTP_SELF']. Does it end a mysqli connection even though you
have not exited the script? Your explanation that $_SERVER['PHP_SELF']
is just a string that contains the script that is being executed makes
sense. I wasn't sure if the connection was being terminated by the
$_SERVER['HTTP_SELF'] variable. Thanks for the help in understanding
this. :)

Schmidty

Jan 24 '07 #5

P: n/a
Why is this not working? I keep getting this error;
Fatal error: Using $this when not in object context in
c:\Inetpub\glendale\network\admin.class.php on line 68

Here is the code class code;
================================================== ==============

<?php

// admin.class.php

class admin{
public $file_path;
public $user;
private $pass;
public $mysqli;

function __construct($user, $pass){
$this->user = $user;
$this->pass = $pass;
$this->dbConnect();

}

function showNewInfo(){

$query1 = "SELECT userID, fname, minit, lname, address, city, state,
zip, phone, useremail, ctype, cnumb, exp, recdate FROM personalinfo
WHERE checked = FALSE";

if ($result = $this->mysqli->real_query($query1)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if

// Show info of users not updated
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'><table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"background: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Credit Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"background: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Current info in database:</td></tr>";
echo "<tr><tr><td colspan='2' style=\"border: 2px solid #000000;
width: 100%;\">";
while($row = $result->fetch_assoc()){
echo "<input type='checkbox' name='perinfo[]'
value='".$row['userID']."' >".$row['userID']." : ".$row['lname']." -
".$row['recdate']."<br />";
} // end while
echo "</td></tr><tr>";
echo "<td align=\"center\"><input style=\"font: 10px solid #000000;\"
type=\"submit\" value=\"UPDATE INFO\" name='updatedb' /></td><td
style=\"text-align: center;\"><input type=\"reset\" style=\"font: 10px
solid #000000;\" value=\"RESET CHOICES\" /></td></tr></form></table>";

$result->free();
} // end function
function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname) or die("ERROR:
Cannot connect to database server");

if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli;
} // end function dbConnect

function dbClose(){
$this->mysqli->close();
} // end function dbClose
function updateDB($perinfo){
foreach($perinfo as $info);
$query3= "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
$info";

if (isset($this->mysqli)) {echo "ERROR on mysqli";
exit;}

$result = $this->mysqli->query($query3);
echo "QUERY DONE";
$result->free();
return true;
} // end function updateDB
} // end class
?>

And here is the script that execute this
--------------------------------------------------------------------------------------------
<?php
print "<br />Hello <b>'$user'</b>.<br />";
print "You are ";
if ($type =='administrator'){
$file_path = $_POST['file_path'] = '';

// Administrators
echo "an <b style='color: #FF0000;'>$type</band have full
administration rights.<br />";
$user = new admin($user, $pass);
$user->showNewInfo();
if (isset($_POST['updatedb'])){ admin::updateDB($_POST['perinfo']); }
}
End example
================================================== =============

Thanks for the help.

Schmidty

On Jan 24, 8:23 am, "Schmidty" <schmi...@baronholding.comwrote:
On Jan 24, 1:26 am, Erwin Moller

<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Schmidty wrote:
So if I do a $_SERVER['PHP_SELF'] in a function within a class that
will end the execution of that class and restart the same script? Do I
need to do all processing in a script before I display a page that will
have a $_SERVER['PHP_SELF'] action? Thanks for the help...
SchmidtyHi,
Please don't toppost. It destroys the order of the conversation.
$_SERVER['PHP_SELF'] is just a string that contains the script that is being
executed.
I do not understand what 'doing a $_SERVER['PHP_SELF'] in a function' means.
But it will most probably NOT terminated the execution of the script.
exit(); does.
You must clearly see the difference between the server and the client
(browser).
Your script produces a form that will be send back to the client (=browser).
Then your script ends.
The form action in your example posts back to the same script (because you
used the target for the action $_SERVER['PHP_SELF']), so if anybody presses
submit, that form will be posted, and hence the same script will be
executed as before.
But the server or PHP couldn't care less, and thinks of it as just another
call to that script.
http-protocol is stateless, this means that NO lasting connection is build
between the client and the server. To overcome this you must use sessions.
And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script ends.
So you'll have to rebuild your connection each invocation of a script that
needs a database.
Hope this helps.
Regards,
Erwin Moller
On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Schmidty wrote:
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...
Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();
if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser
class newuser {
public $name;
private $passwd;
private $mysqli;
function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor
function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";
} // end function
} //end classSchmidty,
>As I explained in comp.database.mysql, you can't. Once a page's
>processing is completed, all connections (and objects) are released.
>You can keep information like user ids, etc. in the $_SESSION variable,
>but not the connection. Even if you could keep the connection info in
>there, the connection itself will be closed.
>Each page is it's own little program. Any external resources opened by
>it are closed at the end of the page processing.
>--
>==================
>Remove the "x" from my email address
>Jerry Stuckle
>JDS Computer Training Corp.
>jstuck...@attglobal.net
>==================- Hide quoted text -- Show quoted text -Thanks Erwin

The Google Groups editor places your reponse at the top when making a
reply. I went ahead posted at the bottom for you...

I understand that HTTP is stateless and I have been using sessions
variables and understand that you can't carry a database connection
through either one. I was confused on what happens with an
$_SERVER['HTTP_SELF'] in a script. What I meant by "doing a
$_SERVER['PHP_SELF'] in a function" is having a page echoed in a
function and having the 'action' of that page execute a
$_SERVER['HTTP_SELF']. Does it end a mysqli connection even though you
have not exited the script? Your explanation that $_SERVER['PHP_SELF']
is just a string that contains the script that is being executed makes
sense. I wasn't sure if the connection was being terminated by the
$_SERVER['HTTP_SELF'] variable. Thanks for the help in understanding
this. :)

Schmidty- Hide quoted text -- Show quoted text -
Jan 24 '07 #6

P: n/a
Schmidty wrote:
>
Thanks Erwin

The Google Groups editor places your reponse at the top when making a
reply. I went ahead posted at the bottom for you...

I understand that HTTP is stateless and I have been using sessions
variables and understand that you can't carry a database connection
through either one. I was confused on what happens with an
$_SERVER['HTTP_SELF'] in a script. What I meant by "doing a
$_SERVER['PHP_SELF'] in a function" is having a page echoed in a
function and having the 'action' of that page execute a
$_SERVER['HTTP_SELF']. Does it end a mysqli connection even though you
have not exited the script? Your explanation that $_SERVER['PHP_SELF']
is just a string that contains the script that is being executed makes
sense. I wasn't sure if the connection was being terminated by the
$_SERVER['HTTP_SELF'] variable. Thanks for the help in understanding
this. :)

Schmidty
Hi, Schmidty,

Yes, Google Groups does that. But then some groups actually prefer top
posting. And you can't make everyone happy :-). This one happens to
like bottom posting (and so do I).

When you say the "action of that page..." do you mean via a FORM tag?
Or a metatag, or what?

But in either case no, actually using $_SERVER['PHP_SELF'] is no
different than any other string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 24 '07 #7

P: n/a
Schmidty wrote:
On Jan 24, 8:23 am, "Schmidty" <schmi...@baronholding.comwrote:
>On Jan 24, 1:26 am, Erwin Moller

<since_humans_read_this_I_am_spammed_too_m...@spa myourself.comwrote:
>>Schmidty wrote:
So if I do a $_SERVER['PHP_SELF'] in a function within a class that
will end the execution of that class and restart the same script? Do I
need to do all processing in a script before I display a page that will
have a $_SERVER['PHP_SELF'] action? Thanks for the help...
SchmidtyHi,
Please don't toppost. It destroys the order of the conversation.
$_SERVER['PHP_SELF'] is just a string that contains the script that is being
executed.
I do not understand what 'doing a $_SERVER['PHP_SELF'] in a function' means.
But it will most probably NOT terminated the execution of the script.
exit(); does.
You must clearly see the difference between the server and the client
(browser).
Your script produces a form that will be send back to the client (=browser).
Then your script ends.
The form action in your example posts back to the same script (because you
used the target for the action $_SERVER['PHP_SELF']), so if anybody presses
submit, that form will be posted, and hence the same script will be
executed as before.
But the server or PHP couldn't care less, and thinks of it as just another
call to that script.
http-protocol is stateless, this means that NO lasting connection is build
between the client and the server. To overcome this you must use sessions.
And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script ends.
So you'll have to rebuild your connection each invocation of a script that
needs a database.
Hope this helps.
Regards,
Erwin Moller
On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidty wrote:
>If you do a page reload with $_SERVER['PHP_SELF'] 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
>I am new to OOP? Thanks...
>Example; ========================================
><?php
> // webpage
> $newsignon = new newuser();
> logon();
> if (isset($_POST['submit'])){
> $newsignon = query("SELECT name, password FROM
>database");
> }
>?>
><?php
> // class newuser
>class newuser {
> public $name;
> private $passwd;
> private $mysqli;
> function __construct(){
> include('dbconn.php');
> $mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
> if (mysqli_connect_errno()){ printf("Can't connect to MySQL
>Server. Errorcode: %s\n", mysqli_connect_error());
> exit;
> }
> $this->mysqli = $mysqli; // is this right?
> } //end constructor
> function query($query){
> if ($result = $this->mysqli->real_query($query)){
> $result = $this->mysqli->store_result();
> if($this->mysqli->error) { echo "ERROR with mysqli stored
> procedure";}
> } // end if
> } // end function
> function logon(){
> echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
>// Would this work?
> echo "<input type='text' name='user' /><br /><input
>type='password' name='passwd' />";
> echo "<input type='submit' value='submit' />";
> } // end function
>} //end classSchmidty,
As I explained in comp.database.mysql, you can't. Once a page's
processing is completed, all connections (and objects) are released.
You can keep information like user ids, etc. in the $_SESSION variable,
but not the connection. Even if you could keep the connection info in
there, the connection itself will be closed.
Each page is it's own little program. Any external resources opened by
it are closed at the end of the page processing.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -- Show quoted text -Thanks Erwin
The Google Groups editor places your reponse at the top when making a
reply. I went ahead posted at the bottom for you...

I understand that HTTP is stateless and I have been using sessions
variables and understand that you can't carry a database connection
through either one. I was confused on what happens with an
$_SERVER['HTTP_SELF'] in a script. What I meant by "doing a
$_SERVER['PHP_SELF'] in a function" is having a page echoed in a
function and having the 'action' of that page execute a
$_SERVER['HTTP_SELF']. Does it end a mysqli connection even though you
have not exited the script? Your explanation that $_SERVER['PHP_SELF']
is just a string that contains the script that is being executed makes
sense. I wasn't sure if the connection was being terminated by the
$_SERVER['HTTP_SELF'] variable. Thanks for the help in understanding
this. :)

Schmidty- Hide quoted text -- Show quoted text -

Why is this not working? I keep getting this error;
Fatal error: Using $this when not in object context in
c:\Inetpub\glendale\network\admin.class.php on line 68

Here is the code class code;
================================================== ==============

<?php

// admin.class.php

class admin{
public $file_path;
public $user;
private $pass;
public $mysqli;

function __construct($user, $pass){
$this->user = $user;
$this->pass = $pass;
$this->dbConnect();

}

function showNewInfo(){

$query1 = "SELECT userID, fname, minit, lname, address, city, state,
zip, phone, useremail, ctype, cnumb, exp, recdate FROM personalinfo
WHERE checked = FALSE";

if ($result = $this->mysqli->real_query($query1)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if

// Show info of users not updated
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'><table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"background: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Credit Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"background: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Current info in database:</td></tr>";
echo "<tr><tr><td colspan='2' style=\"border: 2px solid #000000;
width: 100%;\">";
while($row = $result->fetch_assoc()){
echo "<input type='checkbox' name='perinfo[]'
value='".$row['userID']."' >".$row['userID']." : ".$row['lname']." -
".$row['recdate']."<br />";
} // end while
echo "</td></tr><tr>";
echo "<td align=\"center\"><input style=\"font: 10px solid #000000;\"
type=\"submit\" value=\"UPDATE INFO\" name='updatedb' /></td><td
style=\"text-align: center;\"><input type=\"reset\" style=\"font: 10px
solid #000000;\" value=\"RESET CHOICES\" /></td></tr></form></table>";

$result->free();
} // end function
function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname) or die("ERROR:
Cannot connect to database server");

if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli;
} // end function dbConnect

function dbClose(){
$this->mysqli->close();
} // end function dbClose
function updateDB($perinfo){
foreach($perinfo as $info);
$query3= "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
$info";

if (isset($this->mysqli)) {echo "ERROR on mysqli";
exit;}

$result = $this->mysqli->query($query3);
echo "QUERY DONE";
$result->free();
return true;
} // end function updateDB
} // end class
?>

And here is the script that execute this
--------------------------------------------------------------------------------------------
<?php
print "<br />Hello <b>'$user'</b>.<br />";
print "You are ";
if ($type =='administrator'){
$file_path = $_POST['file_path'] = '';

// Administrators
echo "an <b style='color: #FF0000;'>$type</band have full
administration rights.<br />";
$user = new admin($user, $pass);
$user->showNewInfo();
if (isset($_POST['updatedb'])){ admin::updateDB($_POST['perinfo']); }
}
End example
================================================== =============

Thanks for the help.

Schmidty
(Top posting fixed)

Off hand, I would say your problem is in the line:

admin::updateDB($_POST['perinfo']);

This is calling the function as a class member, not as an object member.
The '::' syntax doesn't pass a $this variable.

Try $user->updateDB($_POST['perinfo']); instead.

If that isn't it, which line gets the error?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 24 '07 #8

P: n/a


On Jan 24, 9:17 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidtywrote:
On Jan 24, 8:23 am, "Schmidty" <schmi...@baronholding.comwrote:
On Jan 24, 1:26 am, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Schmidtywrote:
So if I do a $_SERVER['PHP_SELF'] in a function within a class that
will end the execution of that class and restart the same script? DoI
need to do all processing in a script before I display a page that will
have a $_SERVER['PHP_SELF'] action? Thanks for the help...
SchmidtyHi,
Please don't toppost. It destroys the order of the conversation.
$_SERVER['PHP_SELF'] is just a string that contains the script that is being
executed.
I do not understand what 'doing a $_SERVER['PHP_SELF'] in a function'means.
But it will most probably NOT terminated the execution of the script.
exit(); does.
You must clearly see the difference between the server and the client
(browser).
Your script produces a form that will be send back to the client (=browser).
Then your script ends.
The form action in your example posts back to the same script (because you
used the target for the action $_SERVER['PHP_SELF']), so if anybody presses
submit, that form will be posted, and hence the same script will be
executed as before.
But the server or PHP couldn't care less, and thinks of it as just another
call to that script.
http-protocol is stateless, this means that NO lasting connection is build
between the client and the server. To overcome this you must use sessions.
And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the scriptends.
So you'll have to rebuild your connection each invocation of a scriptthat
needs a database.
Hope this helps.
Regards,
Erwin Moller
On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidtywrote:
If you do a page reload with $_SERVER['PHP_SELF'] 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
I am new to OOP? Thanks...
Example; ========================================
<?php
// webpage
$newsignon = new newuser();
logon();
if (isset($_POST['submit'])){
$newsignon = query("SELECT name, password FROM
database");
}
?>
<?php
// class newuser
class newuser {
public $name;
private $passwd;
private $mysqli;
function __construct(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()){ printf("Can't connect to MySQL
Server. Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli; // is this right?
} //end constructor
function query($query){
if ($result = $this->mysqli->real_query($query)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='password' name='passwd' />";
echo "<input type='submit' value='submit' />";
} // end function
} //end classSchmidty,
As I explained in comp.database.mysql, you can't. Once a page's
processing is completed, all connections (and objects) are released.
You can keep information like user ids, etc. in the $_SESSION variable,
but not the connection. Even if you could keep the connection infoin
there, the connection itself will be closed.
Each page is it's own little program. Any external resources opened by
it are closed at the end of the page processing.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quotedtext -- Show quoted text -Thanks Erwin
The Google Groups editor places your reponse at the top when making a
reply. I went ahead posted at the bottom for you...
I understand that HTTP is stateless and I have been using sessions
variables and understand that you can't carry a database connection
through either one. I was confused on what happens with an
$_SERVER['HTTP_SELF'] in a script. What I meant by "doing a
$_SERVER['PHP_SELF'] in a function" is having a page echoed in a
function and having the 'action' of that page execute a
$_SERVER['HTTP_SELF']. Does it end a mysqli connection even though you
have not exited the script? Your explanation that $_SERVER['PHP_SELF']
is just a string that contains the script that is being executed makes
sense. I wasn't sure if the connection was being terminated by the
$_SERVER['HTTP_SELF'] variable. Thanks for the help in understanding
this. :)
>Schmidty- Hide quoted text -- Show quoted text - Why is this not working? I keep getting this error;
Fatal error: Using $this when not in object context in
c:\Inetpub\glendale\network\admin.class.php on line 68
>
Here is the code class code;
================================================== ==============
>
<?php
>
// admin.class.php
>
class admin{
public $file_path;
public $user;
private $pass;
public $mysqli;
>
function __construct($user, $pass){
$this->user = $user;
$this->pass = $pass;
$this->dbConnect();
>
}
>
function showNewInfo(){
>
$query1 = "SELECT userID, fname, minit, lname, address, city, state,
zip, phone, useremail, ctype, cnumb, exp, recdate FROM personalinfo
WHERE checked = FALSE";
>
if ($result = $this->mysqli->real_query($query1)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if
>
// Show info of users not updated
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'><table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"background: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Credit Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"background: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Current info in database:</td></tr>";
echo "<tr><tr><td colspan='2' style=\"border: 2px solid #000000;
width: 100%;\">";
>
>
while($row = $result->fetch_assoc()){
echo "<input type='checkbox' name='perinfo[]'
value='".$row['userID']."' >".$row['userID']." : ".$row['lname']." -
".$row['recdate']."<br />";
} // end while
echo "</td></tr><tr>";
echo "<td align=\"center\"><input style=\"font: 10px solid #000000;\"
type=\"submit\" value=\"UPDATE INFO\" name='updatedb' /></td><td
style=\"text-align: center;\"><input type=\"reset\" style=\"font: 10px
solid #000000;\" value=\"RESET CHOICES\" /></td></tr></form></table>";
>
$result->free();
} // end function
>
>
function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname) or die("ERROR:
Cannot connect to database server");
>
if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli;
>
>
} // end function dbConnect
>
function dbClose(){
$this->mysqli->close();
} // end function dbClose
>
>
function updateDB($perinfo){
foreach($perinfo as $info);
$query3= "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
$info";
>
if (isset($this->mysqli)) {echo "ERROR on mysqli";
exit;}
>
$result = $this->mysqli->query($query3);
echo "QUERY DONE";
$result->free();
return true;
} // end function updateDB
} // end class
?>
>
And here is the script that execute this
>
---------------------------------------------------------------------------*-----------------
<?php
print "<br />Hello <b>'$user'</b>.<br />";
print "You are ";
if ($type =='administrator'){
$file_path = $_POST['file_path'] = '';
>
// Administrators
echo "an <b style='color: #FF0000;'>$type</band have full
administration rights.<br />";
$user = new admin($user, $pass);
$user->showNewInfo();
if (isset($_POST['updatedb'])){ admin::updateDB($_POST['perinfo']); }
}
End example
================================================== =============
>
Thanks for the help.
>
>Schmidty
>

(Top posting fixed)

Off hand, I would say your problem is in the line:

admin::updateDB($_POST['perinfo']);

This is calling the function as a class member, not as an object member.
The '::' syntax doesn't pass a $this variable.

Try $user->updateDB($_POST['perinfo']); instead.

If that isn't it, which line gets the error?

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

Jerry,

I went ahead and rewrote these two scripts and actually did what you
suggested before I saw your reply (I'm learning slowly but surely) and
it did work but now I am up against a problem with the mysqli
connection. I am getting the error (per my validation) "ERROR: Could
not execute query." from the third line in the function;

Code Example ================================================== =

public function updatedb($userID){
if (!$this->mysqli){ echo "ERROR: Database connection lost.";
$query2 = "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
'$userID'";
$this->mysqli->query($query2) or die("ERROR: Could not execute
query.");
} // end function

End Example ================================================== ==

I had constructed the dbConnect() function when the 'admin' class was
executed. Why does it not carry the mysqli connection? I had assigned a
property with the connection variable in the dbConnect() method. What
happened?

Code Example ================================================== =

public function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);

if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
Errorcode: %s\n", mysqli_connect_error());
exit;
} // end if
return $this->mysqli=$mysqli;
} // end function

End Example ================================================== ===

Did I do right with the line 'return $this->mysqli=$mysqli;' to set the
connection variable to be used later in the function 'updatedb()'?

Hope the examples above help and thanks for any suggestions you might
provide. :)

Schmidty

Jan 24 '07 #9

P: n/a


On Jan 24, 10:26 am, "Schmidty" <schmi...@baronholding.comwrote:
On Jan 24, 9:17 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
Schmidtywrote:
On Jan 24, 8:23 am, "Schmidty" <schmi...@baronholding.comwrote:
>On Jan 24, 1:26 am, Erwin Moller
><since_humans_read_this_I_am_spammed_too_m...@spa myourself.comwrote:
>>>Schmidtywrote:
>>>So if I do a $_SERVER['PHP_SELF'] in a function within a class that
>>>will end the execution of that class and restart the same script? Do I
>>>need to do all processing in a script before I display a page thatwill
>>>have a $_SERVER['PHP_SELF'] action? Thanks for the help...
>>>SchmidtyHi,
>>Please don't toppost. It destroys the order of the conversation.
>>$_SERVER['PHP_SELF'] is just a string that contains the script thatis being
>>executed.
>>I do not understand what 'doing a $_SERVER['PHP_SELF'] in a function' means.
>>But it will most probably NOT terminated the execution of the script.
>>exit(); does.
>>You must clearly see the difference between the server and the client
>>(browser).
>>Your script produces a form that will be send back to the client (=browser).
>>Then your script ends.
>>The form action in your example posts back to the same script (because you
>>used the target for the action $_SERVER['PHP_SELF']), so if anybodypresses
>>submit, that form will be posted, and hence the same script will be
>>executed as before.
>>But the server or PHP couldn't care less, and thinks of it as just another
>>call to that script.
>>http-protocol is stateless, this means that NO lasting connection is build
>>between the client and the server. To overcome this you must use sessions.
>>And as Jerry said: connections to a database are NOT fit to store in a
>>session because PHP destroys all existing connections when the script ends.
>>So you'll have to rebuild your connection each invocation of a script that
>>needs a database.
>>Hope this helps.
>>Regards,
>>Erwin Moller
>>>On Jan 23, 4:54 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>>>>Schmidtywrote:
>>>>>If you do a page reload with $_SERVER['PHP_SELF'] will your program
>>>>>lose a mysqli connection upon the reload of the page? Would thiscode
>>>>>work? I need to know how to carry over a connection between methods as
>>>>>I am new to OOP? Thanks...
>>>>>Example; ========================================
>>>>><?php
>>>>> // webpage
>>>>> $newsignon = new newuser();
>>>>> logon();
>>>>> if (isset($_POST['submit'])){
>>>>> $newsignon = query("SELECT name, password FROM
>>>>>database");
>>>>> }
>>>>>?>
>>>>><?php
>>>>> // class newuser
>>>>>class newuser {
>>>>> public $name;
>>>>> private $passwd;
>>>>> private $mysqli;
>>>>> function __construct(){
>>>>> include('dbconn.php');
>>>>> $mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);
>>>>> if (mysqli_connect_errno()){ printf("Can't connect to MySQL
>>>>>Server. Errorcode: %s\n", mysqli_connect_error());
>>>>> exit;
>>>>> }
>>>>> $this->mysqli = $mysqli; // is this right?
>>>>> } //end constructor
>>>>> function query($query){
>>>>> if ($result = $this->mysqli->real_query($query)){
>>>>> $result = $this->mysqli->store_result();
>>>>> if($this->mysqli->error) { echo "ERROR with mysqli stored
>>>>> procedure";}
>>>>> } // end if
>>>>> } // end function
>>>>> function logon(){
>>>>> echo "<form action='".$_POST['PHP_SELF']."' method='post' >";
>>>>>// Would this work?
>>>>> echo "<input type='text' name='user' /><br /><input
>>>>>type='password' name='passwd' />";
>>>>> echo "<input type='submit' value='submit' />";
>>>>> } // end function
>>>>>} //end classSchmidty,
>>>>As I explained in comp.database.mysql, you can't. Once a page's
>>>>processing is completed, all connections (and objects) are released.
>>>>You can keep information like user ids, etc. in the $_SESSION variable,
>>>>but not the connection. Even if you could keep the connection info in
>>>>there, the connection itself will be closed.
>>>>Each page is it's own little program. Any external resources opened by
>>>>it are closed at the end of the page processing.
>>>>--
>>>>==================
>>>>Remove the "x" from my email address
>>>>Jerry Stuckle
>>>>JDS Computer Training Corp.
>>>>jstuck...@attglobal.net
>>>>==================- Hide quoted text -- Show quoted text -Thanks Erwin
>The Google Groups editor places your reponse at the top when making a
>reply. I went ahead posted at the bottom for you...
>I understand that HTTP is stateless and I have been using sessions
>variables and understand that you can't carry a database connection
>through either one. I was confused on what happens with an
>$_SERVER['HTTP_SELF'] in a script. What I meant by "doing a
>$_SERVER['PHP_SELF'] in a function" is having a page echoed in a
>function and having the 'action' of that page execute a
>$_SERVER['HTTP_SELF']. Does it end a mysqli connection even though you
>have not exited the script? Your explanation that $_SERVER['PHP_SELF']
>is just a string that contains the script that is being executed makes
>sense. I wasn't sure if the connection was being terminated by the
>$_SERVER['HTTP_SELF'] variable. Thanks for the help in understanding
>this. :)
>>Schmidty- Hide quoted text -- Show quoted text - Why is this not working? I keep getting this error;
Fatal error: Using $this when not in object context in
c:\Inetpub\glendale\network\admin.class.php on line 68
Here is the code class code;
================================================== ==============
<?php
// admin.class.php
class admin{
public $file_path;
public $user;
private $pass;
public $mysqli;
function __construct($user, $pass){
$this->user = $user;
$this->pass = $pass;
$this->dbConnect();
}
function showNewInfo(){
$query1 = "SELECT userID, fname, minit, lname, address, city, state,
zip, phone, useremail, ctype, cnumb, exp, recdate FROM personalinfo
WHERE checked = FALSE";
if ($result = $this->mysqli->real_query($query1)){
$result = $this->mysqli->store_result();
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if
// Show info of users not updated
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'><table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"background: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Credit Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"background: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Current info in database:</td></tr>";
echo "<tr><tr><td colspan='2' style=\"border: 2px solid #000000;
width: 100%;\">";
while($row = $result->fetch_assoc()){
echo "<input type='checkbox' name='perinfo[]'
value='".$row['userID']."' >".$row['userID']." : ".$row['lname']."-
".$row['recdate']."<br />";
} // end while
echo "</td></tr><tr>";
echo "<td align=\"center\"><input style=\"font: 10px solid #000000;\"
type=\"submit\" value=\"UPDATE INFO\" name='updatedb' /></td><td
style=\"text-align: center;\"><input type=\"reset\" style=\"font: 10px
solid #000000;\" value=\"RESET CHOICES\" /></td></tr></form></table>";
$result->free();
} // end function
function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname) or die("ERROR:
Cannot connect to database server");
if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
Errorcode: %s\n", mysqli_connect_error());
exit;
}
$this->mysqli = $mysqli;
} // end function dbConnect
function dbClose(){
$this->mysqli->close();
} // end function dbClose
function updateDB($perinfo){
foreach($perinfo as $info);
$query3= "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
$info";
if (isset($this->mysqli)) {echo "ERROR on mysqli";
exit;}
$result = $this->mysqli->query($query3);
echo "QUERY DONE";
$result->free();
return true;
} // end function updateDB
} // end class
?>
And here is the script that execute this
---------------------------------------------------------------------------**-----------------
<?php
print "<br />Hello <b>'$user'</b>.<br />";
print "You are ";
if ($type =='administrator'){
$file_path = $_POST['file_path'] = '';
// Administrators
echo "an <b style='color: #FF0000;'>$type</band have full
administration rights.<br />";
$user = new admin($user, $pass);
$user->showNewInfo();
if (isset($_POST['updatedb'])){ admin::updateDB($_POST['perinfo']); }
}
End example
================================================== =============
Thanks for the help.
>Schmidty
(Top posting fixed)
Off hand, I would say your problem is in the line:
admin::updateDB($_POST['perinfo']);
This is calling the function as a class member, not as an object member.
The '::' syntax doesn't pass a $this variable.
Try $user->updateDB($_POST['perinfo']); instead.
If that isn't it, which line gets the error?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -- Show quoted text -Jerry,

I went ahead and rewrote these two scripts and actually did what you
suggested before I saw your reply (I'm learning slowly but surely) and
it did work but now I am up against a problem with the mysqli
connection. I am getting the error (per my validation) "ERROR: Could
not execute query." from the third line in the function;

Code Example ================================================== =

public function updatedb($userID){
if (!$this->mysqli){ echo "ERROR: Database connection lost.";
$query2 = "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
'$userID'";
$this->mysqli->query($query2) or die("ERROR: Could not execute
query.");
} // end function

End Example ================================================== ==

I had constructed the dbConnect() function when the 'admin' class was
executed. Why does it not carry the mysqli connection? I had assigned a
property with the connection variable in the dbConnect() method. What
happened?

Code Example ================================================== =

public function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbpass, $dbname);

if (mysqli_connect_errno()){ printf("Can't connect to MySQL Server.
Errorcode: %s\n", mysqli_connect_error());
exit;
} // end if
return $this->mysqli=$mysqli;
} // end function

End Example ================================================== ===

Did I do right with the line 'return $this->mysqli=$mysqli;' to set the
connection variable to be used later in the function 'updatedb()'?

Hope the examples above help and thanks for any suggestions you might
provide. :)

Schmidty
Jerry,

I was able to figure it out quite easily!! The $query2 statement in the
first code example should read "UPDATE personalinfo SET checked = TRUE
WHERE userID = '$userID'".

The single quotes around the TRUE should be removed! My bad...

Thanks for your suggestions and help in the previous postings. :)

Schmidty

Jan 24 '07 #10

P: n/a
Rik
On Wed, 24 Jan 2007 19:26:57 +0100, Schmidty <sc******@baronholding.com>
wrote:
connection. I am getting the error (per my validation) "ERROR: Could
not execute query." from the third line in the function;

Code Example ================================================== =

public function updatedb($userID){
if (!$this->mysqli){ echo "ERROR: Database connection lost.";
$query2 = "UPDATE personalinfo SET checked = 'TRUE' WHERE userID=
'$userID'";
$this->mysqli->query($query2) or die("ERROR: Could not execute
query.");
} // end function

End Example ================================================== ==

$this->mysqli->query($query2) or die("ERROR: Could not execute query.
MySQL said: ".$this->mysqli->error);

--
Rik Wasmus
* I'm testing several new newsreaders at the moment. Please excuse
possible errors and weird content. *
Jan 24 '07 #11

P: n/a
Erwin Moller wrote:
And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script ends.
Actually...
http://uk2.php.net/manual/en/feature...onnections.php

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jan 25 '07 #12

P: n/a
Toby Inkster wrote:
Erwin Moller wrote:
>And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script
ends.

Actually...
http://uk2.php.net/manual/en/feature...onnections.php
Well, that is not relevant in this discussion I think.
Persistent connections as implemented by PHP only mean that PHP will not
close the actual databaseconnection, and will reuse it as the username,
password, database, etc are excactly the same.
But this happens behind your back without control (from a scripters
point-of-view) and they are only there to speed up the authentication
process.
This means you still have to rebuild the connection next invocation to the
script because the persistent connection is still ended when the script
ends. (Not really closed, but from the scripts point-of-view it is. You
have to re-authenticate yourself by supplying
username/password/database/etc.)

At least that is how I understand the matter. Am I missing something here?
Very well possible. :-)

Regards,
Erwin Moller

Jan 25 '07 #13

P: n/a
Erwin Moller wrote:
Toby Inkster wrote:
>Erwin Moller wrote:
>>And as Jerry said: connections to a database are NOT fit to store in a
session because PHP destroys all existing connections when the script
ends.
Actually...
http://uk2.php.net/manual/en/feature...onnections.php

Well, that is not relevant in this discussion I think.
Persistent connections as implemented by PHP only mean that PHP will not
close the actual databaseconnection, and will reuse it as the username,
password, database, etc are excactly the same.
But this happens behind your back without control (from a scripters
point-of-view) and they are only there to speed up the authentication
process.
This means you still have to rebuild the connection next invocation to the
script because the persistent connection is still ended when the script
ends. (Not really closed, but from the scripts point-of-view it is. You
have to re-authenticate yourself by supplying
username/password/database/etc.)

At least that is how I understand the matter. Am I missing something here?
Very well possible. :-)

Regards,
Erwin Moller
Nope, you're not missing anything, Erwin. That's how it works.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 25 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.