function __construct() { require_once 'dbConnect.php'; // opening db connection $db = new dbConnect(); $this->conn = $db->connect(); }
/** * constructor **/ function __construct() { require_once dirname(__FILE__) . '/dbConnect.php'; //Open DB connection $db = new dbConnect(); $this->conn = $db->connect(); }
function __construct() { require_once dirname(__FILE__) . '/dbConnect.php'; $db = new dbConnect(); //Connect to database $this->con = $db->connect(); //Select "friends" collection, already defined in config.php $this->col = new MongoCollection($this->con, DB_COLLECTION); }
function createTable($name, $query) { $db = new dbConnect(); global $conn; $result = mysqli_query($db->connect(), "create table if not exists {$name}({$query})"); if (!$result) { die('failed to connect [' . $conn->connect_error . ']'); } echo "Table '{$name}' created already.<br>"; }
<?php /************************************************************ DEPENDENCIES ************************************************************/ require '../../settings.php'; /************************************************************ AJAX REQUEST ************************************************************/ $postdata = file_get_contents("php://input"); $dataobject = json_decode($postdata); $post_id = $dataobject->id; $post_status = $dataobject->status; $post_title = $dataobject->title; $post_date = $dataobject->date; $post_content = $dataobject->input; /************************************************************ DATABASE CONNECTION ************************************************************/ $connection = new dbConnect(); $pdo = $connection->connect(); /************************************************************ QUERY ************************************************************/ $querystring = "UPDATE posts SET post_status = :post_status, post_title = :post_title, post_date = :post_date, post_content = :post_content WHERE id = :post_id"; $preparedstatement = $pdo->prepare($querystring); $preparedstatement->execute(["post_status" => $post_status, "post_title" => $post_title, "post_date" => $post_date, "post_content" => $post_content, "post_id" => $post_id]); echo true;
/** * Creating new record */ public function insertIntoTable($obj, $column_names, $table_name) { $db = new dbConnect(); $this->conn = $db->connect(); $c = (array) $obj; $keys = array_keys($c); $columns = ''; $values = ''; foreach ($column_names as $desired_key) { // Check the obj received. If blank insert blank into the array. if (!in_array($desired_key, $keys)) { ${$desired_key} = ''; } else { ${$desired_key} = $c[$desired_key]; } $columns = $columns . $desired_key . ','; $values = $values . "'" . ${$desired_key} . "',"; } $query = "INSERT INTO " . $table_name . "(" . trim($columns, ',') . ") VALUES(" . trim($values, ',') . ")"; $r = $this->conn->query($query) or die($this->conn->error . __LINE__); if ($r) { $new_row_id = $this->conn->insert_id; $db->disconnect(); return $new_row_id; } else { $db->disconnect(); return NULL; } }