Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

Just wondering if anyone can shed some light and direction to make this pdo class works and sanitize data.

The first part of the code works fine DB extend PDO, but the delete function doesnt work and i would like the delete function to sanitize the data before it performs the delete action, such as check the where clause and sanitize.

Any help is highly appreciated and thanks for reading.

What I have tried:


    class DB extends PDO {
    protected $db_name = "xxxx";
    protected $db_user = "root";
    protected $db_pass = "";
    protected $db_host = "localhost";

    public function __construct() {
        try {
            parent::__construct("mysql:host={$this->db_host};dbname={$this->db_name}", $this->db_user, $this->db_pass);
        } catch (PDOException $e) {
            //echo $e->getMessage();
echo "Failed to connect with MySQL: " . $e->getMessage();
        }    } 
// This where the CURD functions i am having issue, the DBConnect I tried to create the connection is failing.  See my code below:
	public function delete($table,$cond,$limit=1){
      $sql = "DELETE FROM $table WHERE $cond LIMIT $limit ";
      return $this->DBconnect->exec($sql);
    // Validate data
        public function test_input($data) {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            return $data;        }
Updated 30-Jan-19 21:05pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900