[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-12-22
2
Medium Priority
?
111 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 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