Re: mysqli connections and oop



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...@xxxxxxxxxxxxx> wrote:
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...@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • Re: dialup solution (as seconary connection / iptables )
    ... ip-down is launched by pppd only after the PPP link no longer available ... first with MINICOM or is PAP and script not mutualy exclusive? ... do have to "make the connection first with MINICOM." ... If you use the Linux box and route the news IP address to it on each ...
    (comp.os.linux.networking)
  • Re: mysqli connections and oop
    ... need to do all processing in a script before I display a page that will ... But it will most probably NOT terminated the execution of the script. ... this means that NO lasting connection is build ... Why does it not carry the mysqli connection? ...
    (comp.lang.php)
  • Re: mysqli connections and oop
    ... And here is the script that execute this ... lose a mysqli connection upon the reload of the page? ...
    (comp.lang.php)
  • Re: Does apache stop a script mid execution ?
    ... If the user calls a time consuming script and then stops or refreshes ... How does it relate to e.g. a script performing a large mysql query? ... 2.b) how the connection is set up. ... the server stops the script execution. ...
    (comp.lang.php)
  • Re: Keeping pppd alive--how?
    ... >>wrote a script to dial up my ISP, wait 40 seconds, then start up Jay's ... Perhaps using the netstat command to do ... >options tab is an option to redial is connection is lost. ... My Linux machine is text only--no GUIs. ...
    (alt.os.linux.redhat)