I’m new to php and am trying to learn oop. I have a simple input that passes the text to a class to sanitize it. I want to be able to insert the text into the database using pdo. I’m not sure if I’m going the correct way with this.
[code]
$sanitize = new SanitizeText($category);
//I want the sanitize text in the database.
$newdb = new Database();
[code]
class Database {
private $db_user = ‘root’;
private $db_password = ‘password’;
private $db_name = ‘test’;
private $db_host = ‘localhost’;
public $prepare_sql;
public $execute_sql;
// Connect to database
public function __construct() {
try {
new PDO(‘mysql:host=’ .$this->db_host. ‘; dbname=’ .$this->db_name, $this->db_user, $this->db_password);
echo “Connected to database”;
}
catch (PDOException $e) {
echo “Could not connect to database”;
}
}
// Insert data.. not sure if this is proper
public function create() {
$stmt = $this->prepare($prepare_sql);
$stmt->execute($execute_sql);
}
}