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):
Expand|Select|Wrap|Line Numbers
- include("database_connect.php");
- include("query_builder.class.php");
- $text = "Brian O'Dell";
- $query = new QueryBuilder;
- $data = $query->select($text);
DATABASE_CONNECT.PHP:
Expand|Select|Wrap|Line Numbers
- 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.CLASS.PHP:
Expand|Select|Wrap|Line Numbers
- 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;
- }
- }