【发布时间】:2016-07-25 06:24:44
【问题描述】:
我有一个类,用于使用 PDO 连接在表中插入“id”,现在我必须存储表单数据,即会话变量中的 id。
<?php
session_start();
// this class is used to create connection with database
class Database
{
private $db_host = ‘localhost’;
private $db_user = ‘root’;
private $db_pass = ‘root’;
private $db_name = ‘test’;
public function connect() {
$db = new PDO('mysql:host=$db_host;dbname=$db_name;charset=utf8mb4', '$db_user', '$db_pass');
}
}
this class is used to insert the id in the table
class table1 extends Database
{
public function insert_info()
{
$sql = "insert into info(id) values ('?')";
$sql->bind_param("s", $id);
$sql->execute();
return true;
}
}
$_SESSION['campid']='camp1001';
$db = new table1(); // it is used to object of class table1.
$res=$db->insert_info();
?>
如何将会话变量存储在表中将如何实现。
【问题讨论】: