CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   MySQL (http://www.codingforums.com/forumdisplay.php?f=7)
-   -   I need help preparing PDO SELECT. (http://www.codingforums.com/showthread.php?t=285078)

Ax3l 12-31-2012 07:06 PM

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)?

Fou-Lu 12-31-2012 07:41 PM

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).

Ax3l 12-31-2012 07:47 PM

Quote:

Originally Posted by Fou-Lu (Post 1303264)
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.

Fou-Lu 12-31-2012 07:50 PM

In the WHERE clause? Then yep that would be fine.

Ax3l 12-31-2012 08:13 PM

Quote:

Originally Posted by Fou-Lu (Post 1303267)
In the WHERE clause? Then yep that would be fine.

Yes, thank you.


All times are GMT +1. The time now is 04:03 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.