这里摘自php类:
DB.class.php
class DB {
protected $db_name = '';
protected $db_user = '';
protected $db_pass = '';
protected $db_host = '';
protected $connection;
public function connect() {
$this->connection = mysqli_connect($this->db_host, $this->db_user, $this->db_pass);
mysqli_select_db($this->connection, $this->db_name);
return true;
}
public function processRowSet($rowSet, $singleRow = false) {
$resultArray = array();
while ($row = mysqli_fetch_assoc($rowSet)) {
array_push($resultArray, $row);
}
if ($singleRow === true)
return $resultArray[0];
return $resultArray;
}
public function insert($data, $table) {
$columns = "";
$values = "";
foreach ($data as $column => $value) {
$columns .= ($columns == "") ? "" : ", ";
$columns .= $column;
$values .= ($values == "") ? "" : ", ";
$values .= $value;
}
$sql = "insert into $table ($columns) values ($values)";
mysqli_query($this->connection, $sql) or die(mysqli_error($this->connection));
//return the ID of the user in the database.
return mysqli_insert_id($this->connection);
}
}
插入-entry.php
require_once 'db.php';
$headline = $_POST['headline'];
$description = $_POST['description'];
$data = array(
'headline' => $headline,
'description' => $description
);
$db->insert($data, 'entries');´
关于这门课程的专业使用,我有三个问题: