EmployeeServiceg 类连接到 mysql 数据库。我可以从数据库中检索数据,但插入语句有困难,因为 auto_id 返回新的 persid,但所有其他数据库列中只有空值。
提前致谢。
class EmployeeServiceg{
var $username = "root";
var $password = "";
var $server = "localhost";
var $port = "3306";
var $databasename = "hg";
var $tablename = "employees";
var $connection;
public function __construct() {
$this->connection = mysqli_connect(
$this->server,
$this->username,
$this->password,
$this->databasename,
$this->port
);
$this->throwExceptionOnError($this->connection);
}
public function createEmployee($item) {
$stmt = mysqli_prepare($this->connection,
"INSERT INTO employees (name, surname, title, cellphone, email,
streetno, street, city, employeeno, idno)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$this->throwExceptionOnError();
mysqli_bind_param($stmt,'ssssssssss', $row->name, $row->surname, $row->title,
$row->cellphone, $row->email, $row->streetno, $row->street, $row->city,
$row->employeeno, $row->idno);
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$autoid = mysqli_stmt_insert_id($stmt);
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
return $autoid;
}