标签:inf class sql .com res fail roo mysq utf-8
MySql
1.连接数据库
结果是:
》》也可以一条一条的取出来
结果是:
1 <!DOCTYPE html> 2 <html> 3 <meta charset = "UTF-8"> 4 <title>MySql</Title> 5 <head> 6 </head> 7 <body> 8 <?php 9 10 $conn = mysql_connect(‘localhost‘,‘root‘,‘root‘); 11 if($conn) 12 { 13 mysql_select_db(‘php‘,$conn); 14 $result = mysql_query("select * from test"); 15 16 echo ‘mysql数据的条数是:‘.mysql_num_rows($result).‘<br>‘; 17 18 echo "<table style = ‘text-align: left;‘ border = ‘1‘ >"; 19 echo "<tr><th>id</th><th>name</th><th>age</th></tr>"; 20 $count = mysql_num_rows($result); 21 for($i = 0; $i < $count; $i++) 22 { 23 $arr = mysql_fetch_assoc($result); 24 $id = $arr[‘Id‘]; 25 $name = $arr[‘name‘]; 26 $age = $arr[‘age‘]; 27 28 echo "<tr><td>$id</td><td>$name</td><td>$age</td></tr>"; 29 } 30 echo "</table>"; 31 } 32 else 33 { 34 echo ‘faile‘; 35 } 36 ?> 37 </body> 38 39 </html>
:结果是:
需要注意的是:有时候也是可以将php与html混合嵌套使用
2.防止sql注入
所以在向数据库中添数据的时候,要将用户传入的数据进行转换,intval()等,防止恶意注入
具体的防止sql注入连接大佬
标签:inf class sql .com res fail roo mysq utf-8
原文地址:https://www.cnblogs.com/qinzhihaovip/p/9822026.html