mysql知识点总结

一、mysql_connect(),在php7已移除,有mysqli_connect(),pdo,代替。

<?php
header("Content-type:text/html;charset=utf-8");
$dbhost="localhost:3306";//mysql服務器主機地址
$dbuser='root';
$dbpass='root';
$conn=mysqli_connect($dbhost,$dbuser,$dbpass);
if(!$conn){
    die("could not connect :".mysqli_error($conn));
}
echo "Connect successfully<br/>";
//操作数据库
//选择数据库
mysqli_select_db($conn,'wc');
/**创建数据库
$sql='create database if not exists wc';
$retval=mysqli_query($conn,$sql);
if(!$retval){
    die("创建数据库失败!".mysqli_error($conn));
}
echo "创建数据库成功".mysqli_error($conn);
**/

/**创建表
$sql="create table if not exists tb3(".
"id int(4)  auto_increment,".
"title varchar(55) not null default '',".
"author varchar(100) not null default '',".
"date date,".
"primary key(id))engine=innodb;";
**/
/**查询表

$sql="select title,author from tb1";

$res=mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($res)){
    echo "<br/>标题{$row['title']}:{$row['author']}";
}
**/
/**插入表**/
$sql="insert into tb(title,author) values('测试11','eee'),('测试21','aaaa')";
$res=mysqli_query($conn,$sql);

if(!$res){
    echo "创建失败".mysqli_error($conn);
}else{
    echo "创建成功!";
    echo mysqli_affected_rows($conn);
}

//-------end-----



mysqli_close($conn);

 

二、union的使用

三having的使用,

posted @ 2019-02-10 16:40  jiuchen  阅读(348)  评论(0编辑  收藏  举报