在php中打印mysql数据库[重复]

This question already has an answer here:

i have a mysql database name cstudents with table students and sid,sname,sdiv and passyr as the table columns. i intend to print this entire table. here is the code i tried:

$con3=mysql_connect(DB_HOST1,DB_USER1,DB_PASSWORD1) or die ("failed to connect to mysql".mysql_error());
$db=mysql_select_db(DB_NAME1,$con3) or die ("failed to connect to mysql".mysql_error());
$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student;
$result = mysql_query($query) or die ('Error:'.mysql_error($query));
while ($row = mysql_fetch_assoc($result,mysql_both)) {
    echo $row['sid'];
    echo $row['sname'];
    echo $row['sdiv'];
    echo $row['passyr'];
}

executing this gives: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

please help!

</div>

You have missed closing double quotes in your query, instead of:

$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student;

must be:

$query = "SELECT sid, sname, rollno, passyr FROM cstudents.student";

And one suggestion: start using mysqli_* functions instead of already depreciated mysql_*.