public function DeleteData($users, $passwords, $dbName, $table, $id) { $con_user = $users; $con_pass = $passwords; $con_name = $dbName; $connection_object = new connect(); if (!empty($con_user) && !empty($con_pass)) { $dbcon = $connection_object->connection('localhost', $con_user, $con_pass, $con_name); } else { $dbcon = $connection_object->connection('localhost', 'firoz', 'firoz', $con_name); } $sql = "delete from {$table} where `id`={$id}"; //$query=mysql_query($sql); $deleteStatement = $dbcon->prepare($sql); if ($deleteStatement->execute(array(':id' => $id))) { echo "<script> alert('তথ্যটি ডিলিট করা হয়েছে ।')</script>"; echo "<script>location.href='enter.php'</script>"; } else { echo "<script> alert('আপনার ডিলিট করা সম্ভব হয়নি ।')</script>"; echo "<script>location.href='enter.php'</script>"; } }
public function DeleteData($users, $passwords, $dbName, $table, $id) { $con_user = $users; $con_pass = $passwords; $con_name = $dbName; $connection_object = new connect(); if (!empty($con_user) && !empty($con_pass)) { $dbcon = $connection_object->connection('localhost', $con_user, $con_pass, $con_name); } else { $dbcon = $connection_object->connection('localhost', 'root', '', $con_name); } $sql = "delete from {$table} where `id`={$id}"; //$query=mysql_query($sql); $deleteStatement = $dbcon->prepare($sql); $deleteStatement->execute(array(':id' => $id)); }
{ $this->host = $hostname; $this->user = $username; $this->pass = $passwoard; $this->db = $database; $connect = new PDO("mysql:host={$this->host};dbname={$this->db}", $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $connect->setAttribute(PDO::ATTR_PERSISTENT, true); return $connect; } } $connection_object = new connect(); include 'database_config.php'; $db_user = $database_user; $db_pass = $databse_pass; $dbcon = $connection_object->connection('localhost', $db_user, $db_pass, 'student_kpi'); //start from here $batch = $_POST['b_id']; $group = $_POST['g_id']; $student_id = $_POST['s_id']; $std_names = $_POST['name']; $att = $_POST['attendance']; $en_date = $_POST['entry_date']; $preparedStatement = $dbcon->prepare('INSERT INTO student_attendance (s_id, name, b_id, g_id, attendance, entry_date) VALUES (:sid, :sname, :bid, :gid, :atten, :ent_date)'); $arrlength = count($student_id); for ($x = 0; $x < $arrlength; $x++) { $preparedStatement->bindParam(':sid', $student_id[$x]); $preparedStatement->bindParam(':sname', $std_names[$x]); $preparedStatement->bindParam(':bid', $batch); $preparedStatement->bindParam(':gid', $group);
<?php class connect { var $host; var $user; var $pass; var $db; public $connect; public function connection($hostname, $username, $passwoard, $database) { $this->host = $hostname; $this->user = $username; $this->pass = $passwoard; $this->db = $database; $connect = new PDO("mysql:host={$this->host};dbname={$this->db}", $this->user, $this->pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $connect->setAttribute(PDO::ATTR_PERSISTENT, true); return $connect; } } $connection_object = new connect(); $dbcon = $connection_object->connection("localhost", "root", "", "database_name"); //if($dbcon) //{ // echo "Connection establish succesfully."; //}