马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
实例以下实例使用MYSQL_NUM参数显示数据表runoob_tbl的所有记录: <?php$dbhost = 'localhost:3036';$dbuser = 'root';$dbpass = 'rootpassword';$conn = mysql_connect($dbhost, $dbuser, $dbpass);if(! $conn ){ die('Could not connect: ' . mysql_error());}$sql = 'SELECT runoob_id, runoob_title, runoob_author, submission_date FROM runoob_tbl';mysql_select_db('RUNOOB');$retval = mysql_query( $sql, $conn );if(! $retval ){ die('Could not get data: ' . mysql_error());}while($row = mysql_fetch_array($retval, MYSQL_NUM)){ echo "Tutorial ID :{$row[0]} <br> ". "Title: {$row[1]} <br> ". "Author: {$row[2]} <br> ". "Submission Date : {$row[3]} <br> ". "--------------------------------<br>";}echo "Fetched data successfully\n";mysql_close($conn);?>以上三个实例输出结果都一样。 内存释放在我们执行完SELECT语句后,释放游标内存是一个很好的习惯。 。可以通过PHP函数mysql_free_result()来实现内存的释放。 以下实例演示了该函数的使用方法。 实例尝试以下实例: <?php$dbhost = 'localhost:3036';$dbuser = 'root';$dbpass = 'rootpassword';$conn = mysql_connect($dbhost, $dbuser, $dbpass);if(! $conn ){ die('Could not connect: ' . mysql_error());}$sql = 'SELECT runoob_id, runoob_title, runoob_author, submission_date FROM runoob_tbl';mysql_select_db('RUNOOB');$retval = mysql_query( $sql, $conn );if(! $retval ){ die('Could not get data: ' . mysql_error());}while($row = mysql_fetch_array($retval, MYSQL_NUM)){ echo "Tutorial ID :{$row[0]} <br> ". "Title: {$row[1]} <br> ". "Author: {$row[2]} <br> ". "Submission Date : {$row[3]} <br> ". "--------------------------------<br>";}mysql_free_result($retval);echo "Fetched data successfully\n";mysql_close($conn);?>
|