0

Is it possible to use * in query for $stmt->prepare() and using bind_result()?
For example I have to select 50 columns in 1 table with conditions as parameter, and if I type all 50 columns it will take time. So in this scenario how can I get the result?

$stmt->prepare("Select * from table where col1 = ? and col2=? and col3=? and col4=?")
$stmt->bind_param("ssss",$col1, $col2, $col3, $col4)
$stmt->execute()
Dharman
  • 30,962
  • 25
  • 85
  • 135
blitzen12
  • 1,350
  • 3
  • 24
  • 33
  • Typing all 50 columns will take time once. NOT typing all 50 columns will take extra time everytime the query is executed. Your choice. – Gerald Schneider Mar 24 '14 at 10:47
  • also not typing the 50 column names on the first time may take hours and hours of additional debugging time later. – bansi Mar 24 '14 at 10:49

3 Answers3

4

Yes, of course.
Just use $res = $stmt->get_result() followed by familiar $row = $res->fetch_assoc() stuff

However, for a newbie, you are indeed strictly advised to choose PDO over mysqli.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • after reading this. http://stackoverflow.com/questions/13569/mysqli-or-pdo-what-are-the-pros-and-cons. PDO is a lot better than mysqli. so I guess I have to change my application. – blitzen12 Mar 24 '14 at 15:17
0

Only the question mark is used as a placeholder character by mysqli, so you can use * just as you usually would.

-1

To save time, if you are using PDO, you can name your parameters and then mass assign them.
E.g.

$sql = 'SELECT *
    FROM table
    WHERE col1=:myval OR col2=:myval OR col3=:myval';
$sth = $dbh->prepare($sql);
$sth->execute(array(':myval ' => 150));
$red = $sth->fetchAll();
James T
  • 499
  • 2
  • 5
  • Updated my answer. I completely missed that mysqli keyword (mistook it for mysql) and assumed PDO due to the prepare statement – James T Mar 24 '14 at 10:51