Solved

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

Posted on 2014-12-22
2
106 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 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 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