Solved

Transitioning to PDO/MySQL.  Need help  with two INSERT statements on one query

Posted on 2014-12-22
2
103 Views
Last Modified: 2014-12-22
Is it possible to have two insert statements on one query with PDO?  (Need one for Level 0 and one for level 1 as shown below)

$query6 = $conn->query('SELECT DISTINCT catidexp1 FROM download');

$statement = $conn->prepare('INSERT IGNORE INTO category_path (category_id,path_id,level) VALUES(:catid,:pathid,:level)');

$statement2 = $conn->prepare('INSERT IGNORE INTO category_path (category_id,path_id,level) VALUES(:catid,:pathid,:level)');

while ($row6 = $query6->fetch(PDO::FETCH_ASSOC)){
	
		$params = array(':catid'=>$row6['catidexp1'],':pathid'=>$row6['catidexp1'],':level'=>"0");
		$statement->execute($params); 

$params = array(':catid'=>$row6['catidexp1'],':pathid'=>$row6['catidexp1'],':level'=>"1");
		$statement->execute($params); 
	
}

Open in new window

0
Comment
Question by:lawrence_dev
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40513489
Yes, you only need the one statement as they are doing the same thing

$query6 = $conn->query('SELECT DISTINCT catidexp1 FROM download');

$statement = $conn->prepare('INSERT IGNORE INTO category_path (category_id,path_id,level) VALUES(:catid,:pathid,:level)');

while ($row6 = $query6->fetch(PDO::FETCH_ASSOC)){
	$params = array(':catid'=>$row6['catidexp1'],':pathid'=>$row6['catidexp1'],':level'=>"0");
	$statement->execute($params); 

	$params = array(':catid'=>$row6['catidexp1'],':pathid'=>$row6['catidexp1'],':level'=>"1");
	$statement->execute($params); 
}

Open in new window

0
 

Author Closing Comment

by:lawrence_dev
ID: 40513763
Thanks for your help Gary!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question