您好,我正在尝试将 url 及其内容插入到 2 个表中,但我将使用表中的 id 并将此 id 插入到第二个表中的多个条目中,我希望我能成功地澄清我的问题,我可以查看数据,但我无法使用 pdo 在 mysql 中插入数据,我在 mysql 中得到的所有内容都是 NULL 值是我的代码,用于更多说明
首先我的类文件是这样的 Links.php
/**
* Sets the object's properties using the values in the supplied array
*
* @param assoc The property values
*/
public function __construct1( $data=array() ) {
if ( isset( $data['listURL'] ) ) $this->listURL = $data['listURL'];
if ( isset( $data['hostname'] ) ) $this->hstname = $data['hostname'];
}
/**
* Sets the object's properties using the values in the supplied array
*
* @param assoc The property values
*/
public function __construct2( $data=array() ) {
if ( isset( $data['stringName'] ) ) $this->stringName = $data['stringName'];
if ( isset( $data['stringUrl'] ) ) $this->stringUrl = $stringUrl = $data['stringUrl'];
}
/**
* Sets the object's properties using the edit form post values in the supplied array
*
* @param assoc The form post values
*/
public function storeFormValues1 ( $params ) {
// Store all the parameters
$this->__construct1( $params );
}
/**
* Sets the object's properties using the edit form post values in the supplied array
*
* @param assoc The form post values
*/
public function storeFormValues2 ( $params ) {
// Store all the parameters
$this->__construct2( $params );
}
public function insertlistFuncClass() {
$conn = new PDO(DB_NDS, DB_USERNAME, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$sql = "INSERT INTO lists ( listURL, hostname ) VALUES (:listURL, :hostname)";
$st = $conn->prepare($sql);
$st->bindValue( ":listurl", $this->url, PDO::PARAM_STR );
$st->bindValue( ":hostname", $this->hstname, PDO::PARAM_STR );
$st->execute();
$listId = $conn->lastInsertId();
$conn = null;
}
}
慕虎7371278