using pdo want to echo 3 columns from one row

how can I do a select statement
I want one row from table1 using pdo
select table1.column1, table1.column2, table1.column3 where table.id=449

want to echo
table1.column1, table1.column2, table1.column3
LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
Are you sure it is table.Id instead of table1.id? Anyway look at this

<?php
$sth = $dbh->prepare("select table1.column1, table1.column2, table1.column3 where table.id=449");
$sth->execute();



$result = $sth->fetch(PDO::FETCH_ASSOC);
echo $result['column1'] . '\n' . $result['column2'] . '\n' . $result[column3'] . '\n';

Open in new window


You find more in Php manual: http://php.net/manual/en/pdostatement.fetch.php

Cheers
0
Ray PaseurCommented:
This article maps the various MySQL extensions.  The part about table.id=449 that you probably want is in the PDO::Prepare() method, where you would bind the variable containing the table.id.  Or the table1.id, depending.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

If you want one row, do yourself a favor and use LIMIT 1.  See AntiPractice #26
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12293-AntiPHPatterns-and-AntiPHPractices.html
0
rgb192Author Commented:
$sth = $dbh->prepare("select table1.column1, table1.column2, table1.column3 where table.id=449");
$sth->execute();


http://php.net/manual/en/pdo.prepare.php

what about the pdo connection?
db, hostname, username, password

object oriented versus procedural? as in mysqli?
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Marco GasiFreelancerCommented:
For connection see here: http://www.php.net/manual/en/pdo.connections.php
AFAIK, there is no procedural version of PDO, but only oop implementation, which I prefer always:

$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
PDO is object-oriented.  There is no procedural version (nor should there be)!
http://php.net/manual/en/pdo.connections.php

Search this article for Connect to the Server and Choose the Data Base
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
rgb192Author Commented:
thank you for connection string
and explanation about object oriented only implementation.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.