当前位置:Gxlcms > 数据库问题 > MySQL NULL 值处理

MySQL NULL 值处理

时间:2021-07-01 10:21:17 帮助过:20人阅读

$dbhost = ‘localhost:3306‘; // mysql服务器主机地址 $dbuser = ‘root‘; // mysql用户名 $dbpass = ‘123456‘; // mysql用户名密码 $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die(‘连接失败: ‘ . mysqli_error($conn)); } // 设置编码,防止中文乱码 mysqli_query($conn , "set names utf8"); if( isset($runoob_count )) { $sql = "SELECT runoob_author, runoob_count FROM runoob_test_tbl WHERE runoob_count = $runoob_count"; } else { $sql = "SELECT runoob_author, runoob_count FROM runoob_test_tbl WHERE runoob_count IS NULL"; } mysqli_select_db( $conn, ‘RUNOOB‘ ); $retval = mysqli_query( $conn, $sql ); if(! $retval ) { die(‘无法读取数据: ‘ . mysqli_error($conn)); } echo ‘<h2>菜鸟教程 IS NULL 测试<h2>‘; echo ‘<table border="1"><tr><td>作者</td><td>登陆次数</td></tr>‘; while($row = mysqli_fetch_array($retval, MYSQL_ASSOC)) { echo "<tr>". "<td>{$row[‘runoob_author‘]} </td> ". "<td>{$row[‘runoob_count‘]} </td> ". "</tr>"; } echo ‘</table>‘; mysqli_close($conn); ?>

 

MySQL NULL 值处理

标签:str   其它   sql   query   strong   无法读取   返回   查找   HERE   

人气教程排行