详解MySQL中WHERE子句的用法

2019-01-05 09:52:08王旭

实例:

下面的例子将返回tutorials_tbl表中作者的名字是Sanjay所有记录:

<?php $dbhost = 'localhost:3036'; $dbuser = 'root'; $dbpass = 'rootpassword'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'SELECT tutorial_id, tutorial_title, tutorial_author, submission_date FROM tutorials_tbl WHERE tutorial_author="Sanjay"'; //by www.jb51.net mysql_select_db('TUTORIALS'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not get data: ' . mysql_error()); } while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) { echo "Tutorial ID :{$row['tutorial_id']} <br> ". "Title: {$row['tutorial_title']} <br> ". "Author: {$row['tutorial_author']} <br> ". "Submission Date : {$row['submission_date']} <br> ". "--------------------------------<br>"; } echo "Fetched data successfullyn"; mysql_close($conn); ?>

您可能感兴趣的文章:

UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexistsMYSQL where 1=1判定中的作用说明MYSQL WHERE语句优化