Re: mysqli connections and oop
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Tue, 23 Jan 2007 19:54:37 -0500
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.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: mysqli connections and oop
- From: Schmidty
- Re: mysqli connections and oop
- References:
- mysqli connections and oop
- From: Schmidty
- mysqli connections and oop
- Prev by Date: Re: Email Encryption
- Next by Date: Re: i can not get addslashes/stripslashes to have the same effect on different servers
- Previous by thread: mysqli connections and oop
- Next by thread: Re: mysqli connections and oop
- Index(es):
Relevant Pages
|