">

Binds variables to a prepared statement for result storage (original) (raw)

<?php $link = mysqli_connect("localhost", "my_user", "my_password", "world");/* check connection */ if (!$link) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }/* prepare statement */ if ($stmt = mysqli_prepare($link, "SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) { mysqli_stmt_execute($stmt);/* bind variables to prepared statement */ mysqli_stmt_bind_result($stmt, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>o</mi><mi>l</mi><mn>1</mn><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">col1, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">co</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord">1</span><span class="mpunct">,</span></span></span></span>col2);/* fetch values */ while (mysqli_stmt_fetch($stmt)) { printf("%s %s\n", <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>c</mi><mi>o</mi><mi>l</mi><mn>1</mn><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">col1, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">co</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord">1</span><span class="mpunct">,</span></span></span></span>col2); }/* close statement */ mysqli_stmt_close($stmt); }/* close connection */ mysqli_close($link); ?>

AFG Afghanistan ALB Albania DZA Algeria ASM American Samoa AND Andorra