How do I print rows from my table in the MYSQL server when I run the php file? I have used the prepare statement to prepare a query. I am not sure how to output the result of that query. My code is as follows:
// Check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
putenv("ODBCINI=/etc/dwwdwd.ini");
putenv("NZ_ODBC_INI_PATH=/etc/");
putenv("LD_LIBRARY_PATH=/export/home/joadf/netezza/lib64");
echo "Whats up";
$lvar = $coni->prepare(
'SELECT * FROM TABLE A limit 10');
$lvar->execute();
$lvar->fetch();
?>
You are going to use
bind_result()Doc. There are examples on that page. Basically you use bind result to set the variables where the data from the query is stored and then read them that way. You should put the fetch part inside awhileloop so you can iterate over the resultsYou will have n number of varaible within the
bind_result()statement depending on how many cols you want from the db.Example if requesting 3 cols from db
$lvar->bind_result($a, $b, $c);Now $a, $b, $c contain the data of the first row in the order that the cols are listed after calling
$lvar->fetch().Each time you call
$lvar->fetch()the variables are updated until there are no more rows at which case the fetch statement returnsfalseThis code should do the trick