Hello,
I am trying to add a session variable that is an object that contains all of the MySQL queries I need to use to interact with my database. Currently, I call the constructor of my object on each page.
Attached is my test file (testSession.php)
When this test page redirects, I receive the following output (I echo back the query from the PrayerDatabase object to make sure the query is correct):
PrayerDatabase extends Database. My problem is that the SQL query works normally. However, when I try to retrieve the same PrayerDatabase object from a session variable, I cannot execute the same query. Does anyone know why this session variable did not store the MySQL link to my database? Thank you very much for your time.
Thank you,
Nick Ruiz
I am trying to add a session variable that is an object that contains all of the MySQL queries I need to use to interact with my database. Currently, I call the constructor of my object on each page.
Attached is my test file (testSession.php)
Code:
<?php
// testSession.php
require_once("scripts/PrayerDatabase.php");
session_start();
if(!(isset($_GET["revisit"])))
{
$db = new PrayerDatabase();
//session_register("db");
$_SESSION["db"] = $db;
$rs = $db->selectUserById(1);
if($rs)
{
print("Query successful");
}
else
print("Query failed");
print("<script language='javascript'>document.location='testSession.php?revisit=true';</script>");
}
else
{
phpinfo();
$db = $_SESSION["db"];
$rs = $db->selectUserById(1);
if($rs)
{
print("Query successful");
}
else
print("Query failed");
}
?>
When this test page redirects, I receive the following output (I echo back the query from the PrayerDatabase object to make sure the query is correct):
Code:
SELECT txt_fname, txt_lname, txt_picurl, txt_about, DATE_FORMAT(dt_birthday, '%m/%d/%y'), DATE_FORMAT(dt_created, '%M %d, %Y'), DATE_FORMAT(dt_updated, '%M %d, %Y'), txt_email FROM users WHERE id_user = '1' LIMIT 1
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/.../scripts/Database.php on line 42
Query failed.
PrayerDatabase extends Database. My problem is that the SQL query works normally. However, when I try to retrieve the same PrayerDatabase object from a session variable, I cannot execute the same query. Does anyone know why this session variable did not store the MySQL link to my database? Thank you very much for your time.
Thank you,
Nick Ruiz