473,704 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysqli connections and oop

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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if

} // end function

function logon(){
echo "<form action='".$_POS T['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
13 3711
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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if

} // end function

function logon(){
echo "<form action='".$_POS T['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.m ysql, 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*******@attgl obal.net
=============== ===
Jan 24 '07 #2
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...@attg lobal.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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POS T['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.m ysql, 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...@attgl obal.net
=============== ===
Jan 24 '07 #3
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...@attg lobal.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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POS T['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.m ysql, 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...@attg lobal.net
============== ====
Jan 24 '07 #4


On Jan 24, 1:26 am, Erwin Moller
<since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
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...@attg lobal.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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POS T['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.m ysql, 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...@attgl obal.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
Why is this not working? I keep getting this error;
Fatal error: Using $this when not in object context in
c:\Inetpub\glen dale\network\ad min.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($us er, $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($qu ery1)){
$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='".$_SER VER['PHP_SELF']."' method='post'>< table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"backgro und: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Cred it Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"backgro und: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Curr ent info in database:</td></tr>";
echo "<tr><tr><t d 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;\"><inpu t 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($perin fo){
foreach($perinf o 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 =='administrato r'){
$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...@baron holding.comwrot e:
On Jan 24, 1:26 am, Erwin Moller

<since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
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...@attg lobal.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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POS T['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.m ysql, 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...@attg lobal.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
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*******@attgl obal.net
=============== ===
Jan 24 '07 #7
Schmidty wrote:
On Jan 24, 8:23 am, "Schmidty" <schmi...@baron holding.comwrot e:
>On Jan 24, 1:26 am, Erwin Moller

<since_humans_ read_this_I_am_ spammed_too_m.. .@spamyourself. 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...@attg lobal.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($qu ery)){
> $result = $this->mysqli->store_result() ;
> if($this->mysqli->error) { echo "ERROR with mysqli stored
> procedure";}
> } // end if
> } // end function
> function logon(){
> echo "<form action='".$_POS T['PHP_SELF']."' method='post' >";
>// Would this work?
> echo "<input type='text' name='user' /><br /><input
>type='pass word' name='passwd' />";
> echo "<input type='submit' value='submit' />";
> } // end function
>} //end classSchmidty,
As I explained in comp.database.m ysql, you can't. Once a page's
processin g 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...@a ttglobal.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\glen dale\network\ad min.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($us er, $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($qu ery1)){
$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='".$_SER VER['PHP_SELF']."' method='post'>< table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"backgro und: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Cred it Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"backgro und: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Curr ent info in database:</td></tr>";
echo "<tr><tr><t d 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;\"><inpu t 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($perin fo){
foreach($perinf o 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 =='administrato r'){
$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($_POS T['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*******@attgl obal.net
=============== ===
Jan 24 '07 #8


On Jan 24, 9:17 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Schmidtywrote:
On Jan 24, 8:23 am, "Schmidty" <schmi...@baron holding.comwrot e:
On Jan 24, 1:26 am, Erwin Moller
<since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
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...@attg lobal.netwrote:
Schmidtywro te:
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($qu ery)){
$result = $this->mysqli->store_result() ;
if($this->mysqli->error) { echo "ERROR with mysqli stored
procedure";}
} // end if
} // end function
function logon(){
echo "<form action='".$_POS T['PHP_SELF']."' method='post' >";
// Would this work?
echo "<input type='text' name='user' /><br /><input
type='passw ord' name='passwd' />";
echo "<input type='submit' value='submit' />";
} // end function
} //end classSchmidty,
As I explained in comp.database.m ysql, 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...@at tglobal.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\glen dale\network\ad min.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($us er, $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($qu ery1)){
$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='".$_SER VER['PHP_SELF']."' method='post'>< table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"backgro und: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Cred it Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"backgro und: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Curr ent info in database:</td></tr>";
echo "<tr><tr><t d 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;\"><inpu t 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($perin fo){
foreach($perinf o 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 =='administrato r'){
$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($_POS T['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...@attgl obal.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($userI D){
if (!$this->mysqli){ echo "ERROR: Database connection lost.";
$query2 = "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
'$userID'";
$this->mysqli->query($query 2) 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


On Jan 24, 10:26 am, "Schmidty" <schmi...@baron holding.comwrot e:
On Jan 24, 9:17 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Schmidtywrote:
On Jan 24, 8:23 am, "Schmidty" <schmi...@baron holding.comwrot e:
>On Jan 24, 1:26 am, Erwin Moller
><since_humans_ read_this_I_am_ spammed_too_m.. .@spamyourself. comwrote:
>>>Schmidtywrot e:
>>>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...@attg lobal.netwrote:
>>>>>Schmidtywr ote:
>>>>>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($qu ery)){
>>>>> $result = $this->mysqli->store_result() ;
>>>>> if($this->mysqli->error) { echo "ERROR with mysqli stored
>>>>> procedure";}
>>>>> } // end if
>>>>> } // end function
>>>>> function logon(){
>>>>> echo "<form action='".$_POS T['PHP_SELF']."' method='post' >";
>>>>>// Would this work?
>>>>> echo "<input type='text' name='user' /><br /><input
>>>>>type='pass word' name='passwd' />";
>>>>> echo "<input type='submit' value='submit' />";
>>>>> } // end function
>>>>>} //end classSchmidty,
>>>>As I explained in comp.database.m ysql, you can't. Once a page's
>>>>processin g 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...@a ttglobal.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\glen dale\network\ad min.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($us er, $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($qu ery1)){
$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='".$_SER VER['PHP_SELF']."' method='post'>< table
style=\"font: 14px solid #000000; border: 2px solid #CCC000;\">";
echo "<tr><td colspan='2' style=\"backgro und: #C0C0C5; text-align:
center; font: 16px solid #000000;\">Cred it Card
Applications</td></tr>";
echo "<tr><td colspan='2' style=\"backgro und: #FFFFE0; text-align:
left; font: 11px solid #000000;\">Curr ent info in database:</td></tr>";
echo "<tr><tr><t d 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;\"><inpu t 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($perin fo){
foreach($perinf o 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 =='administrato r'){
$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($_POS T['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...@attgl obal.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($userI D){
if (!$this->mysqli){ echo "ERROR: Database connection lost.";
$query2 = "UPDATE personalinfo SET checked = 'TRUE' WHERE userID =
'$userID'";
$this->mysqli->query($query 2) 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

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

Similar topics

0
1889
by: yzzzzz | last post by:
Hi, I am compiling PHP 5.0.2 myself with MySQL support. I did a ./configure --with-mysqli=/usr/local/mysql/bin/mysql_config (see end of post for complete configure) Note: I also have --with-mysql=/usr/local/mysql/. However, I get the same errors when I configure without the mysql extension, just mysqli. And as the documentation says, I use the same version of MySQL for both extensions to avoid conflicts.
0
2136
by: Roy Shaw | last post by:
When configuring PHP5 (5.0.3) to use the mysqli libraries I get a "No such file or directory" from the configure script. My goal is to get PHP5 running with mysql 4.1.09 with both the mysql and mysqli options. I can get it to configure and work correctly with just the mysql but NOT the mysqli or both. Environment: Red Hat Enterprise Linux 3, rel 4 php 5.0.3 from sources from php.net
1
2266
by: Mark | last post by:
hello! mysqli in PHP5 comes with prepared statements functionality. However, without persistent connections or connection pooling in this code library, one has to ask: why bother? are prepared statements 'remembered' by the server for a while between connections, so that new connections can take advantage of them, or are they really only useful for those pages/requests that are executing a huge amount of DML in a single shot.
0
2810
by: jonndoe45 | last post by:
Hi, Am using PHP-CGO, MYSQL and am having to connect to the MYSQL server every time that a query is run. I wrote this connection function (below) in a vain attempt to try and limit the number of connections, but doesn't seem to help. I know you can't store the connection resource in a session var as resources cant be stored in session vars. Does anyone have any ideas ? code ? tricks or settings that they can please advise me with,...
12
4746
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'); define('DB_PASSWORD', 'practical'); define('DB_DATABASE', 'ajax'); // connect to the database $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
2
2766
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 off without a hitch, but I noticed that phpMyAdmin was not able to utilize the MySQLi library (which was working with my last 5.1.x release). As I was looking through php_info(), I noticed that MySQLi didn't even load. However, when I restarted...
21
7275
by: Daz | last post by:
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;
1
3817
by: eholz1 | last post by:
Hello PHP Group, Is there any advantages (or disadvantages) in using mysqli instead of mysql (querys, connections to database, etc). I am currently using mysql_connect, and things like this: $result = @mysql_query("SELECT * FROM images3 WHERE id=" . $img . " AND p=" .$p. ""); to access my database. I see that some people are using the
2
3208
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 below I must call mysqli->connect() each time I call class methods. How do I create an connection for hole object, so methods can do queries without connect each time? Best Regards, Michael
0
8684
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9271
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9134
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9025
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8975
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6604
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4438
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3134
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 we have to send another system
3
2078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.