繁体   English   中英

$ wpdb-> insert()不在表中插入记录

[英]$wpdb->insert() does not Insert record in a table

我试图理解并掌握$ wpdb全局对象,但似乎无法使其工作。 基本上,我试图将单个记录插入wordpress DB中的自定义表中。 我没有创建自己的连接字符串并使用它,而是看到Global $ wpdb对象为我们解决了问题。 我遵循了法典示例,尝试自己做,但是失败了。 我没有收到任何错误,但记录也未插入。 解决问题已经花了几个小时。 您的帮助将不胜感激。 提前致谢。

码:

<?php
class Listings{

    private $buisnessName;
    private $contactName;
    private $categories;
    private $websiteURL;
    private $telephoneNum;
    private $address;
    private $socialLinks;
    private $shortDescription;
    private $images;
    private $fullDescription;
    private $tags;

    function __construct($buisnessName, $contactName, $categories, $websiteURL, $telephoneNum,$address,$socialLinks, $shortDescription, $images, $fullDescription,$tags){

        $this->buisnessName = $buisnessName;
        $this->contactName = $contactName;
        $this->categories = $categories;
        $this->websiteURL = $websiteURL;
        $this->telephoneNum = $telephoneNum;
        $this->address = $address;
        $this->socialLinks = $socialLinks;
        $this->shortDescription = $shortDescription;
        $this->images = $images;
        $this->fullDescription = $fullDescription;
        $this->tags = $tags;        
    }

    function Insert_Listing(){
        global $wpdb;
        $wpdb->insert('wp_listings_info', array("Buisness_Name" => $this->buisnessName,"Contact_Name" => $this->contactName, "Categories" => $this->categories, "Website_URL" => $this->websiteURL, "Telephone_Number" => $this->telephoneNum, "Address" => $this->address, "Social_Network_Links" => $this->socialLinks, "Short_Description" => $this->shortDescription, "Images" => $this->images, "Full_Description" => $this->fullDescription, "Tags" => $this->tags), array("%s", "%s","%s", "%s","%s", "%s","%s", "%s","%s", "%s","%s"));
    }

}
?>

表结构:

CREATE TABLE IF NOT EXISTS `wp_listings_info` (
`L_ID` int(11) NOT NULL AUTO_INCREMENT,
`Business_Name` varchar(100) NOT NULL,
`Contact_Name` varchar(100) NOT NULL,
`Categories` varchar(100) NOT NULL,
`Website_URL` varchar(150) NOT NULL,
`Telephone_Number` varchar(20) NOT NULL,
`Address` varchar(250) NOT NULL,
`Social_Network_Links` varchar(500) NOT NULL,
`Short_Description` text NOT NULL,
`Images` varchar(100) NOT NULL,
`Full_Description` text NOT NULL,
`Tags` varchar(500) NOT NULL,
 PRIMARY KEY (`L_ID`)
)

我这样调用类的对象:

$listingObj = new Listings($buisnessName, $contactName, $categories, $websiteURL, $telephoneNum,$address, $socialLinks, $shortDescription, $images, $fullDescription,$tags);
$listingObj->Insert_Listing();

我再次说我根本没有任何错误,只是代码没有插入记录。 帮助将不胜感激。 谢谢。

Business_Name一样的Buisness_Name (I / S切换左右)。 在您的WP查询中修复它。

$wpdb->insert('wp_listings_info', array("Buisness_Name" => $this->buisnessName ..
//                                         ^^

和您的create语句:

CREATE TABLE IF NOT EXISTS `wp_listings_info` (
...
`Business_Name` varchar(100) NOT NULL,
// ^^
...
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM