DATA INSERT INTO MYSQL DATABASE THROUGH PDO PROCESS

<?php

class Student{
protected $db_connect;
public function __construct(){
$host_name = 'localhost';
$user_name = 'root';
$password = '';
$db_name = 'db_test';

try{
$this->db_connect = new PDO("mysql:host={$host_name}; dbname={$db_name}",$user_name,$password);

}catch(PDOException $e){
echo $e->getMessage();
}

}

public function save_student_info($data){
$student_info = $this->db_connect->prepare("INSERT INTO tbl_student(student_name,phone_number,email_address) VALUES(:a,:b,:c)");
$student_info->bindParam(':a',$data['student_name']);
$student_info->bindParam(':b',$data['phone_number']);
$student_info->bindParam(':c',$data['email_address']);

$student_info->execute();
}
}

Comments

Popular posts from this blog

WP register_post_type() with custom CMB2 meta box

Git post receive setup at server for git push to the production from local machine