I am attempting to connect to the database (which was successfully). However, I can not extend the connection to execute other functions. In my example below,
the output is not giving me what I expected. There seem to be two connections and my escaped text which I called ($data = $query->select($text); ) does not execute.
OUTPUT:
Connection established! Now:Connection established! Now:
text passed =Brian O'Dell
text can be escaped =
INDEX.PHP (main page):
DATABASE_CONNEC T.PHP:
QUERY_BUILDER.C LASS.PHP:
the output is not giving me what I expected. There seem to be two connections and my escaped text which I called ($data = $query->select($text); ) does not execute.
OUTPUT:
Connection established! Now:Connection established! Now:
text passed =Brian O'Dell
text can be escaped =
INDEX.PHP (main page):
Code:
include("database_connect.php");
include("query_builder.class.php");
$text = "Brian O'Dell";
$query = new QueryBuilder;
$data = $query->select($text);
DATABASE_CONNEC T.PHP:
Code:
public $host = 'localhost';
public $db_username = 'root';
public $db_password = 'password';
public $db_name = 'customer';
protected $mysqli;
public function __construct() {}
public function connect()
{
$this->mysqli = new mysqli($this->host,$this->db_username,$this->db_password,$this->db_name);
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
}
else
{
echo "Connection established! Now:";
}
}
public function db_close()
{
$this->mysqli->close();
}
public function __destruct() {}
QUERY_BUILDER.C LASS.PHP:
Code:
class QueryBuilder
{
public function __construct()
{
$this->connect = Db_Connect::connect();
}
public function __destruct()
{
Db_Connect::db_close();
}
public function select($sql=false)
{
echo "<br>text passed =".$sql."<br>";
$newtxt = $this->mysqli->real_escape_string($sql);
echo "text can be escaped = ".$newtxt;
}
}
Comment