如何插入具有绑定值和内部连接的表? [英] How Can I Insert Into Table With Bind Value And Inner Join?

查看:55
本文介绍了如何插入具有绑定值和内部连接的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我试图在表中使用bindvalue获取数据并使用相同的查询从另一个表中获取ID表...



  $ query  = $ conection-> prepare(  INSERT INTO`post`(`Titel`,`Prioriteit`,`Image`,`Samenvatting`,` Post`,`Poster`,`Datum`)VALUES(:titel,:prioriteit,:image,:samenvatting,:post,:poster,:datum)); 
// met bindvalue worden alle values gebonden aan de parameters van de class
$ query-> bindValue( :titel,trim($ this-> titel,< span class =code-string> ),PDO :: PARAM_STR);
$ query-> bindValue( :prioriteit,$ max + 1,PDO: :PARAM_STR);
$ query-> bindValue( :image,trim($ this-> ; image, ),PDO :: PARAM_STR);
$ query-> bindValue( :samenvatting,trim($ this-> ; samenvatting, ),PDO :: PARAM_STR);
$ query-> bindValue( :post,trim($ this-> ; post, ),PDO :: PARAM_STR);
$ query-> bindValue( :poster,$ _SESSION [ userId],PDO :: PARAM_STR);
// huidige datum word opgeslagen
$ date = date(' Ymd H:i:s');
$ query-> bindValue( :datum,($ date),PDO :: PARAM_STR);
$ query-> execute();

$ query3 = $ conection-> prepare( INSERT INTO`tag`(`Content`,`Blog_id`)SELECT':content',posts.id AS`Blog_id` FROM`tag`INNER JOIN`post` ON tags.Blog_id = posts。 ID);

$ query3-> bindValue( :content,trim( $ this-> tags, ),PDO :: PARAM_STR);
$ query3->执行();







我继续获取:内容列,而不是数据我给了绑定值,如果我尝试值它确实工作,但我认为内部连接不会那样工作..内部连接无论如何都不工作。





我试图获得的是,如果我使用此查询,它应填充内容列,同时从此行中存储的posts表中获取ID。



抱歉英文不好,

解决方案

查询 =


conection-> prepare( INSERT INTO`post`(`Titel`,`Prioriteit`,`Image`,` Samenvatting`,`Post`,`Poster`,`Datum`)VALUES(:titel,:prioriteit,:image,:samenvatting,:post,:poster,:datum));
// met bindvalue worden alle values gebonden aan de parameters van de class


query-> bindValue( :titel,trim(

hey,

Im stuck for a while with trying to get data using bindvalue in a table and using the same query to get ID from a other table into this table...

$query = $conection->prepare("INSERT INTO `posts`(`Titel`, `Prioriteit`, `Image`,`Samenvatting`, `Post`, `Poster`, `Datum`) VALUES (:titel, :prioriteit, :image, :samenvatting, :post, :poster, :datum)");
                                   // met bindvalue worden alle values gebonden aan de parameters van de class
                                   $query->bindValue(":titel", trim($this->titel, " "), PDO::PARAM_STR);
                                   $query->bindValue(":prioriteit", $max+ 1, PDO::PARAM_STR);
                                   $query->bindValue(":image", trim($this->image, " "), PDO::PARAM_STR);
                                   $query->bindValue(":samenvatting", trim($this->samenvatting, " "), PDO::PARAM_STR);
                                   $query->bindValue(":post", trim($this->post, " "), PDO::PARAM_STR);
                                   $query->bindValue(":poster", $_SESSION["userId"], PDO::PARAM_STR);
                                   // huidige datum word opgeslagen
                                   $date = date('Y-m-d H:i:s');
                                   $query->bindValue(":datum",($date) , PDO::PARAM_STR);
                                   $query->execute();

                                   $query3 = $conection->prepare("INSERT INTO `tags`( `Content`, `Blog_id`) SELECT ':content', posts.id AS `Blog_id` FROM `tags` INNER JOIN `posts` ON tags.Blog_id=posts.id");

                                   $query3->bindValue(":content", trim($this->tags, " "), PDO::PARAM_STR);
                                   $query3->execute();




im keep getting :content in the column instead of the data i gave the bindvalue, if i try Value it does work but i think the innerjoin wont work that way.. the innerjoin doesnt work anyway tho.


What im trying to get is if i use this query it should fill the content collumn and at the same time get the ID from the posts table stored in this row.

Sorry for bad english,,

解决方案

query =


conection->prepare("INSERT INTO `posts`(`Titel`, `Prioriteit`, `Image`,`Samenvatting`, `Post`, `Poster`, `Datum`) VALUES (:titel, :prioriteit, :image, :samenvatting, :post, :poster, :datum)"); // met bindvalue worden alle values gebonden aan de parameters van de class


query->bindValue(":titel", trim(


这篇关于如何插入具有绑定值和内部连接的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆