How to display a MySQL column value with PDO in PHP? -


I want to display a column in PHP. For PDOs, I use this code:

  $ db1 = new PDF ('mysql: host = localhost; dbname = db; charset = utf8', 'root', '' ); $ Db1- & gt; Set Attribution (PDO :: ATTROOSACLENLLS, PDO :: NULLOSOTOTTI);  

And this code does not work:

  $ qry = $ db1-> Prepare ("select user_data where user_id = $ userid"); $ Line = mysql_fetch_array ($ sql); Echo ['user_name'] per line;  

How to do that?

Thank you!

Edit:

My code:

  $ db1 = new PDO ('mysql: host = localhost; dbname = db; charset = utf8 ',' Root ',' '); $ Db1- & gt; Set Attribution (PDO :: ATTROOSACLENLLS, PDO :: NULLOSOTOTTI); $ Qry = $ db1- & gt; Prepare (select user_id from user_data; user_id =: id range1 '); $ Qry - & gt; Execution (array (': id' = & gt; $ userid)); $ Line = $ sth - & gt; Bring (); Echo $ qry - & gt; User name;  

And it's not eating anything

and I want to search by $ userid, and echo the user_name column (eg user_id = 1 and this name echo) < / P>

mysql_fetch_array is not for pdo, but rather oo-pdo for the set of original mysql function

fetchColumn () requires you to use the following, only the column will return, so that you can use it in a loop to get the entire column () Ti will return

In addition, as stated in another answer is wrong with your SQL query start. The table name is not included in it.

You are never calling the execution () on the statement; I firmly recommend that you read all the pdo


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -