I am a newbie with MySQL(actually MySQLI), PHP5 and OOP and had a
question that probably relates to other groups but since this group is
heavily trafficated I thought someone might have an answer here;
When I refresh/reload a page in PHP using $_SERVER['PHP_SELF'] I
believe that I am losing the database connection or I am not properly
applying my OOP skills when using MySQLI and cl***es and methods. How
do I keep a connection even with a page refresh and moving between a
script and the cl***?
I have a members page that uses an 'admin.cl***.php' with the admin
cl*** and the database connection function in it. I seem to lose the
connection when moving from the constructor into another function. Is
this what a persistent connection does? I know that MySQLI doesn't
support persistent connections and to be honest, from what I have read,
I don't think I want a persistent connection. So how do I keep the
connections alive between methods (functions) in my cl***?
Example Code
================================================== ===========
<?php
// admin.cl***.php
cl*** admin{
public $file_path;
public $user;
private $p***;
public $result;
public $mysqli;
function showNewInfo(){
$this->dbConnect();
$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_***oc()){
echo "<input type='checkbox' name='perinfo[]'
value='".$row['userID']."' >".$row['userID']." : ".$row['lname']." -
".$row['recdate']."<br />";
} // end while
echo "</td></tr><tr>";
echo "<td style=\"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();
$this->dbClose();
} // end function
function dbConnect(){
include('dbconn.php');
$mysqli = new mysqli($dbnet, $dbuser, $dbp***, $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;
} // end if
$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 (!$this->mysqli) {echo "ERROR on mysqli"; exit;}
$result = $this->mysqli->query($query3);
echo "QUERY DONE";
$result->free();
return true;
} // end function updateDB
} // end cl***
End Example Code
================================================== ==============
Thanks for any help anyone might provide! Like I said; I am still
learning this stuff!!!!
Schmidty