在PHP和MySQL中从SELECT查询中分配变量

How do I query a database using a SELECT statement and then assign the value from the query as a variable?

Here is one possible way:

<?php
$dbcon = mysql_connect("localhost","user","password");
if (!$dbcon)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("database_name", $dbcon);

$query_result = mysql_query("SELECT * FROM MyTable");

while($result_array = mysql_fetch_array($query_result))
  {
  echo $result_array['column1'] . " " . $result_array['column2'];
  echo "<br />";
  }

mysql_close($dbcon);
?>