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>"; }
如何把一个sql文件里的内容通过php代码执行
最新推荐文章于 2021-03-11 11:58:43 发布