亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將值作為 null 插入數據庫

將值作為 null 插入數據庫

PHP
回首憶惘然 2023-07-21 16:24:06
您好,我正在嘗試將 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;}}  
查看完整描述

1 回答

?
慕虎7371278

TA貢獻1802條經驗 獲得超4個贊

我找到了一個我剛剛使用的解決方案,global我將它放在 file.php 的兩個函數中,并且它起作用了

global $listId; 但我必須從這個文件而不是從類中插入。


查看完整回答
反對 回復 2023-07-21
  • 1 回答
  • 0 關注
  • 152 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號