php操作数据库常用命令 php中数据库怎么设计( 九 )


例子:
?php
//注意 php版本要 小于等于 5.3
header("content-type:text/html;charset=utf-8");
$link=mysql_connect("127.0.0.1",'root','root') or die('连接数据库错误');
mysql_select_db("test",$link) or die('选择数据库错误');
//mysql_select_db 第二个参数可要可不要 就近原则
mysql_query("set names utf8");
$sql='select * from bumen';
$res=mysql_query($sql);
?
?php
//服务器端文件代码:
//header头前不能有输出
header("content-type:text/html;charset=utf-8");
//接受用户注册的信息
$name=$_POST['username'];
$pwd=$_POST['pwd'];
$sex=$_POST['sex'];
$bumen=$_POST['bumen'];
$jianjie=$_POST['jianjie'];
//① 连接数据库 mysql_connect('数据库的ip','管理员名称','密码'); 返回一个数据库连接标识是个资源
$link=mysql_connect('127.0.0.1','root','root')or die("数据库连接失败");
//② 选择数据库 mysql_select_db('库名',数据库的连接标识)
mysql_select_db('tt',$link);
echo mysql_error();
die;
//③ 设置数据库的字符集 mysql_query('set namesutf8')
mysql_query('set names utf8');
//④ 写sql语句进行执行 , 增、删、改、查都可以的 用mysql_query()来执行
//注意:mysql_query()对于select返回的是一个资源 , 其他的也就是delete、insert、update返回的都是布尔也就是真或者假
$sql="insert into yuangong (name,pwd,sex,bumen,jianjie)values('$name','$pwd','$sex','$bumen','$jianjie')";
if(mysql_query($sql)){
echo "添加成功php操作数据库常用命令!";
}else{
echo "添加失败!";
}
?
数据库可视化操作工具
navicat (window安装收费)
phpmyadmin(免费跨平台,不用安装 php)
php mysqli 常用函数有哪些php中 mysqli 是个类,这个类php操作数据库常用命令的函数(方法)有php操作数据库常用命令:
mysqli::$affected_rows — Gets the number of affected rows in a previous MySQL operation
mysqli::autocommit — 打开或关闭本次数据库连接php操作数据库常用命令的自动命令提交事务模式
mysqli::begin_transaction — Starts a transaction
mysqli::change_user — Changes the user of the specified database connection
mysqli::character_set_name — 返回当前数据库连接的默认字符编码
mysqli::$client_info — Get MySQL client info
mysqli::$client_version — Returns the MySQL client version as a string
mysqli::close — 关闭先前打开的数据库连接
mysqli::commit — 提交一个事务
mysqli::$connect_errno — Returns the error code from last connect call
mysqli::$connect_error — Returns a string description of the last connect error
mysqli::__construct — Open a new connection to the MySQL server
mysqli::debug — Performs debugging operations
mysqli::dump_debug_info — 将调试信息输出到日志
mysqli::errno — 返回最近函数调用的错误代码
mysqli::$error_list — Returns a list of errors from the last command executed
mysqli::$error — Returns a string description of the last error
mysqli::$field_count — Returns the number of columns for the most recent query
mysqli::get_charset — Returns a character set object
mysqli::get_client_info — Get MySQL client info
mysqli_get_client_stats — Returns client per-process statistics
mysqli_get_client_version — 作为一个整数返回MySQL客户端的版本
mysqli::get_connection_stats — Returns statistics about the client connection
mysqli::$host_info — 返回一个表述使用的连接类型的字符串
mysqli::$protocol_version — 返回MySQL使用的协议版本号
mysqli::$server_info — 返回MySQL服务器的版本号
mysqli::$server_version — 作为一个整数返回MySQL服务器的版本