php 字符串及连接数据库基本知识点
<?php $a1="hello";$a2="hell"; echo strlen($a1); echo strcmp($a1,$a2)."<br/>"; //拆分字符串 $str="hello|nihao|worde|name"; $arr1=explode("|",$str); echo $arr1[2]."<br/>"; //数组转化为字符串 $arr2=array("11","22","33","44","55"); echo implode($arr2)." "; //替换字符串,从某个位置开始替换 $th=substr_replace($a1,"bb",0,2); echo $th."<br/>"; //替换字符串,原有字符替换成新的 $s = "hello"; $a = str_replace("l","a",$s); echo $a."<br/>"; //截取字符串 $jq=substr($s,0,3); echo $jq; //字符在字符串中的位置 $s1="nihao"; echo strpos($s1,h); $host="localhost"; $uid="root"; $pwd="root"; $database="info"; $conn=mysql_connect($host,$uid,$pwd); if($conn==false){echo "连接失败";}else{echo "连接成功";} mysql_select_db($database,$conn); mysql_query("create database xuexi,$conn"); $result= mysql_query("select * from DL"); $ss=""; while( $row=mysql_fetch_row($result)) { $ss=$ss.$row[2]." "; } echo $ss; //1生成连接对象 $db = new mysqli($host,$uid,$pwd,$database); //2.判断是否连接成功 if(mysqli_connect_error()) { echo "连接失败!"; exit; //退出 } //执行MYSQL语句 $result=$db->query("select * from DL"); $zz="<select>"; //遍历数组中数据,做下拉菜单 while($row = $result->fetch_row()/*获取返回值,返回是数组*/) { $zz = $zz."<option value='".$row[1]."'>".$row[2]."</option>"; } $zz."</select>"; echo $zz;