1. <?php 2. require 'config.php'; 3. //新增一条数据 4. /*$sql='insert into tbl_sysuser 5. (usercode,username,password,usertype,isActived) 6. values 7. ("fc01","刘汪洋","w1251314","房产局管理员","YES");'; 8. @mysql_query($sql) or die('SQL错误,新增用户错误:'.mysql_error()); 9. */ 10. 11. //修改数据 12. /* $sql='update tbl_sysuser set username="蔡倩倩" where usercode="fc01"'; 13. * @mysql_query($sql) or die('SQL错误,修改用户错误:'.mysql_error()); 14. * */ 15. 16. //删除数据 17. /* $sql='delete from tbl_sysuser where usercode="fc01"'; 18. * @mysql_query($sql) or die('SQL错误,删除用户错误:'.mysql_error()); 19. * */ 20. $sql='select id,usercode,username,password,usertype,isActived from tbl_sysuser'; 21. 22. 23. $result =@mysql_query($sql) or die('SQL错误,错误信息'.mysql_error()); 24. 25. while($row =mysql_fetch_array($result)) 26. { 27. echo 'username:'.$row['username'].'----password:'.$row['password'].'<br/>'; 28. 29. } 30. 31. mysql_close(); 32. ?>
config.php
1. <?php 2. header('Content-Type:text/html;charset=utf-8'); 3. 4. //常量参数 5. define('DB_HOST','localhost'); 6. define('DB_USER','root'); 7. define('DB_PWD','root'); 8. define('DB_NAME','housing'); 9. 10. //第一步,连接数据库 11. $conn = @mysql_connect(DB_HOST,DB_USER,DB_PWD) or die('数据库连接失败,错误信息:'.mysql_error()); 12. 13. //第二步,选择指定的数据库,设置字符集 14. mysql_select_db(DB_NAME) or die('数据库错误,错误信息:'.mysql_error()); 15. mysql_query('set names UTF8') or die('字符集设置错误'.mysql_error()); 16. 17. ?>