ds2128629 2018-04-15 12:01
浏览 59

为什么MySql没有用php存储布尔值

I have a database table with two columns that have been set as boolean. Whenever I store something in the table everything works correctly except the boolean columns are always false. The columns are featured post and published.

I am using php 7.1.1 and MariaDB 10.1.21 on my xampp local installation.

Output of show table:

CREATE TABLE `posts` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `title` varchar(255) NOT NULL,
    `content` text NOT NULL,
    `seo_description` varchar(255) NOT NULL,
    `featured_post` tinyint(1) NOT NULL DEFAULT '0',
    `published` tinyint(1) NOT NULL DEFAULT '0',
    `seo_title` varchar(255) NOT NULL,
    `post_type` enum('blog','product') NOT NULL,
    `featured_image_id` int(11) NOT NULL,
    `category_id` int(11) NOT NULL,
     PRIMARY KEY (`id`),
     UNIQUE KEY `title` (`title`),
     UNIQUE KEY `seo_title` (`seo_title`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT

Php code defining onr of the variables, the other is exactly the same:

if(isset($_POST["published"])){
    $published = sanitizeInput($_POST["published"]);

    if($published){  //test to see if correct values where being sent and they were
        echo json_encode("boolean true"); 
    } else {
        echo json_encode("boolean false");
    }
} else {
    $published = false;
}


$query = "insert into posts "
        . "(title, content, seo_description, featured_post, published, seo_title, post_type, category_id) "
        . "values "
        . "(:title, :content, :seo_description, :featured_post, :published, :seo_title, :post_type, :category_id)";

$stmt = $pdo->prepare($query);

$stmt->bindValue("featured_post",   $featuredPost,  PDO::PARAM_BOOL);
$stmt->bindValue("published",       $published,     PDO::PARAM_BOOL);
$stmt->bindValue("title",           $title);
$stmt->bindValue("content",         $content);
$stmt->bindValue("seo_description", $seoDescription);
$stmt->bindValue("seo_title",       $seoTitle);
$stmt->bindValue("post_type",       $postType);
$stmt->bindValue("category_id",     $categoryId);

$stmt->execute();   

Any help would be much appreciated.

Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器