php的mysqli模块相关操作记录
2010-10-25 18:57
239 查看
$i= 0;
$str_error = "";
//创建一个连接
$conn = mysqli_connect("domain","uid","password","dbName");
if (mysqli_connect_errno())
exit();
$conn_local = mysqli_connect("domain","uid","password","dbName");
if (mysqli_connect_errno())
exit();
//设置为utf8编码格式
mysqli_query($conn,"set names 'utf8'");
mysqli_query($conn_local,"set names 'utf8'");
$str_sql="select * from table_name order by id limit 100";
$str_insert = "insert into table_other(id, name, age) values(?,?,?)";
//执行查询语句
$rowArray = mysqli_query($conn,$str_sql);
while($row=mysqli_fetch_array($rowArray))
{
$id = $row[0];
$name = $row[1];
$age = $row[2];
//用mysqli_prepare执行插入操作有效避免SQL注入式攻击
if($stmt=mysqli_prepare($conn_local,$str_insert))
{
//绑定参数--第二个参数可选 i(int) d(double) s(string) b(corresponding variable is a blob and will be send in packages)
mysqli_stmt_bind_param($stmt, "sss", $id, $name , $age );
//执行
mysqli_stmt_execute($stmt);
if(mysqli_errno($conn)==0||mysqli_errno($conn)=='1062')
$i++;
else
$str_error .= "insert into table_other(id,name,age) values($id,$name,$age)";
}
}
//关闭连接
mysqli_close($conn);
mysqli_close($conn_local);
echo $str_error;
$str_error = "";
//创建一个连接
$conn = mysqli_connect("domain","uid","password","dbName");
if (mysqli_connect_errno())
exit();
$conn_local = mysqli_connect("domain","uid","password","dbName");
if (mysqli_connect_errno())
exit();
//设置为utf8编码格式
mysqli_query($conn,"set names 'utf8'");
mysqli_query($conn_local,"set names 'utf8'");
$str_sql="select * from table_name order by id limit 100";
$str_insert = "insert into table_other(id, name, age) values(?,?,?)";
//执行查询语句
$rowArray = mysqli_query($conn,$str_sql);
while($row=mysqli_fetch_array($rowArray))
{
$id = $row[0];
$name = $row[1];
$age = $row[2];
//用mysqli_prepare执行插入操作有效避免SQL注入式攻击
if($stmt=mysqli_prepare($conn_local,$str_insert))
{
//绑定参数--第二个参数可选 i(int) d(double) s(string) b(corresponding variable is a blob and will be send in packages)
mysqli_stmt_bind_param($stmt, "sss", $id, $name , $age );
//执行
mysqli_stmt_execute($stmt);
if(mysqli_errno($conn)==0||mysqli_errno($conn)=='1062')
$i++;
else
$str_error .= "insert into table_other(id,name,age) values($id,$name,$age)";
}
}
//关闭连接
mysqli_close($conn);
mysqli_close($conn_local);
echo $str_error;
相关文章推荐
- PHP MysqlI操作数据库
- php操作mysqli(示例代码)
- PHP 数据库操作 mysqli
- PHP中的图像相关函数操作
- php文件操作相关类实例
- 在写php时遇到的PHPExcel相关问题记录(含excel与mysql交互代码)
- php数据库操作常用相关函数
- PHP数据库操作之基于 Mysqli 的数据库操作类库
- PHP数据库操作之基于Mysqli的数据库操作类库
- [EntLib]微软企业库5.0 学习之路——第九步、使用PolicyInjection模块进行AOP—PART4——建立自定义Call Handler实现用户操作日志记录
- PHP 数组操作积累记录
- elasticsearch Document相关操作记录
- 实战 php调用java类由java类读数据库完成相关操作(Inber Write)
- 用PHP进行MySQL删除记录操作代码
- 利用Rsyslog集中收集系统日志和用户操作记录以及相关处理方法
- Mysql导出导入相关操作记录
- php字符串操作相关(2)
- Nginx在线服务状态下平滑升级或新增模块的详细操作记录
- 数据库操作相关(sql语句-php)
- 解析在PHP中使用mysqli扩展库对mysql的操作