Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-31-2012, 07:06 PM   PM User | #1
Ax3l
New Coder

 
Join Date: Aug 2012
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ax3l is an unknown quantity at this point
I need help preparing PDO SELECT.

Code:
if (isset($_GET['Country'])) {
if ($_GET['Country']) {
	
$nr = $db->query("SELECT count(*)from test WHERE Country = '$_GET[Country]'")->fetchColumn();
}
}
How would I go about preparing a statement like this where the value I am selecting is dynamic (As in user chosen)?
Ax3l is offline   Reply With Quote
Old 12-31-2012, 07:41 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The value, as in country?
PHP Code:
if ($stmt $pdo->prepare('SELECT count(*) FROM test WHERE Country = :country'))
{
    
$stmt->execute(array(':country' => $_GET['Country']));
    
$count $stmt->fetchAll();

Unless you mean dynamic userchosen as the properties to fetch, then the answer is no you cannot use binding for that (you cannot create a dynamic structure on a prepared statement).
Fou-Lu is offline   Reply With Quote
Old 12-31-2012, 07:47 PM   PM User | #3
Ax3l
New Coder

 
Join Date: Aug 2012
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ax3l is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
The value, as in country?
PHP Code:
if ($stmt $pdo->prepare('SELECT count(*) FROM test WHERE Country = :country'))
{
    
$stmt->execute(array(':country' => $_GET['Country']));
    
$count $stmt->fetchAll();

Unless you mean dynamic userchosen as the properties to fetch, then the answer is no you cannot use binding for that (you cannot create a dynamic structure on a prepared statement).
I mean the value in the Country field is user chosen.
Ax3l is offline   Reply With Quote
Old 12-31-2012, 07:50 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
In the WHERE clause? Then yep that would be fine.
Fou-Lu is offline   Reply With Quote
Old 12-31-2012, 08:13 PM   PM User | #5
Ax3l
New Coder

 
Join Date: Aug 2012
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Ax3l is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
In the WHERE clause? Then yep that would be fine.
Yes, thank you.
Ax3l is offline   Reply With Quote
Reply

Bookmarks

Tags
mysql, pdo, php, select

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:25 PM.


Advertisement
Log in to turn off these ads.