Home > php教程 > php手册 > mysql一些方法

mysql一些方法

WBOY
Release: 2016-06-06 20:01:17
Original
1261 people have browsed it

dirname(__FILE__); //得到的是文件所在层目录名 注意:在 Windows 中,正斜线(/)和反斜线(/)都可以用作目录分隔符。在其它环境下是斜线(/)。 define('TIME', time());//定义常量 echo gmdate('D, d M Y H:i:s', TIME); //输出常量 require dirname(__F

 dirname(__FILE__);  //得到的是文件所在层目录名
注意:在 Windows 中,正斜线(/)和反斜线(/)都可以用作目录分隔符。在其它环境下是斜线(/)。

define('TIME', time());//定义常量
echo gmdate('D, d M Y H:i:s', TIME); //输出常量

require dirname(__FILE__).'/chen_class/mysqlconn.php';    //引用外部文件


@是在程序出现错误时,屏蔽错误信息,不把错误信息显示在页面上.

//输出本页编码为utf-8
header("content-type:text/html; charset=utf-8");

//三种取值方法
$_REQUEST[]
$_POST[]
$_GET[]


//定义类
class mysql_access
{
function conn()
{
$dbh = mysql_connect('110.110.110.36','root','111111');
mysql_select_db('1234',$dbh);
$query ="select * from phpcms_ask_actor;";
//mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");
mysql_query("set names utf8;");
$res = mysql_query($query, $dbh);
mysql_query("INSERT INTO phpcms_ask_actor(typeid,grade,actor,MIN,MAX) VALUES(5,'陈建平','是一个大好人!',4,5);");
}
}
?>

//php连接mssql数据库
$dbhost="110.110.110.39";
 $dbuser="sa";
 $dbpwd="111111";
 $my_conn=@mssql_connect($dbhost,$dbuser,$dbpwd) or die("数据库连接错误!");

 mssql_select_db('pubs',$my_conn);

 $sql=mssql_query(iconv('UTF-8',"gbk","insert into jobs(job_desc,min_lvl,max_lvl) values('陈建',34,45)")); //解决汉字输入问题
 $result =@mssql_query($sql,$my_conn);
 mssql_close($my_conn);

extract($_POST);
//相当于$username = $_POST['username'];
//$password = $_POST['password'];

//页面调用类
$mysql_access = new mysql_access;
$mysql_access->conn();

//字符串相加
$output = " "; //必须要空一格否则与其它字符串相加也为空。
$output=$output."daddd";

//剪除指定字符
trim($strings,",");
trim($strings) ;     //参数2为空时默认去掉头尾空格,制表,换行,回车,空值。

//截取字符串
substr($str4,2,45); //第2个参数代表起始位置的索引值(从0开始,取值包括),第三个参数代表要取字符个数

//替换字符串
str_replace("aa","bb","chen aa aa",$i); //第一个参数old字符串,第二个参数新字符串,第三参数要编辑的字符串[,第四个参数指替换字符串的个数]


//数组

自动分配 ID 键:
$names = array("Peter","Quagmire","Joe");
//取值
$names[0]


//关联数组
$ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
//取值
$ages['Peter']
array_keys($memberinfo);//取数组键值
//自动取出数组,并用第一个参数分隔开
implode(' ', $memberinfo)


//多维数组:

$families = array
(
  "Griffin"=>array("Peter","Lois","Megan"),
  "Quagmire"=>array("Glenn"),
  "Brown"=>array("Cleveland","Loretta","Junior")
);

//取值
$families['Griffin'][2]

 

 

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template