码迷,mamicode.com
首页 > 数据库 > 详细

php 字符串及连接数据库基本知识点

时间:2015-12-16 17:01:27      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

<?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)."&nbsp";

//替换字符串,从某个位置开始替换
$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]."&nbsp";
		 }
	   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;

  

php 字符串及连接数据库基本知识点

标签:

原文地址:http://www.cnblogs.com/dcdgmjzhal/p/5051392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!