如何把一个sql文件里的内容通过php代码执行
2016-06-21 20:50
941 查看
if (@$link= mysql_connect("$host","$name","$pwd")){ $db_selected = mysql_select_db("$db", $link); if($db_selected){ $sql="drop database ".$post['db']; mysql_query($sql); } $sql="create database ".$post['db']; mysql_query($sql); $file=file_get_contents('./assets/we3.sql'); $arr=explode('-- ----------------------------',$file); $db_selected = mysql_select_db($post['db'], $link); for($i=0;$i<count($arr);$i++){ if($i%2==0){ $a=explode(";",trim($arr[$i])); array_pop($a); foreach($a as $v){ mysql_query($v); } } } $str="<?php return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=".$post['dbhost'].";port=3306;dbname=".$post['db']."', 'username' => '".$post['dbname']."', 'password' => '".$post['dbpwd']."', 'charset' => 'utf8', 'tablePrefix' => 'we_', //加入前缀名称we_ ];"; file_put_contents('../config/db.php',$str); $sql="insert into we_user (uname,upwd) VALUES ('$uname','$upwd')"; mysql_query($sql); mysql_close($link); $counter_file = 'assets/existence.php';//文件名及路径,在当前目录下新建aa.txt文件 $fopen = fopen($counter_file,'wb');//新建文件命令 fputs($fopen, 'aaaaaa ');//向文件中写入内容; fclose($fopen); $this->redirect(array('/login/login')); }else{ echo "<script> if(alert('数据库账号或密码错误')){ location.href='index.php?r=install/two'; }else{ location.href='index.php?r=install/two'; } </script>"; }
相关文章推荐
- 简单实现jdbc连接数据库通用工具类(代码)
- MySql 改变表中已有字段的长度
- MySql 为表中已有字段设置默认值
- python 写的sqli_lab显错式注入小代码
- sqli_lab
- 【MySQL】笔记
- mysql中函数CONCAT及GROUP_CONCAT的使用
- postgresql使用正则匹配IP地址
- mysqldump使用方法
- DOM解析XML文件并添加到数据库中
- 如何使用MySQL的 group_concat函数
- MySQL下载安装、配置与使用(win7x64)
- MySQL ERROR 1045 (28000): Access denied for user 'root'@'localhost'
- mysql数据库连接总结
- mysql 获取自增值
- 《SQL必知必会》16-18章笔记
- message from server: "Host xxx is not allowed to connect to this MySQL server的解決
- CAS SSO 4.0.x 用户数据库验证
- MySQL存储过程游标示例
- DataTruncation数据错误