windwild 发表于 2012-2-16 16:53:20

如何执行sql文件呢

我将建好的数据库用phpmyadmin到处为sql文件以后希望能方便的初始化网站
简单的说就是怎样才能导入sql文件中的脚本到CI中执行呢?


$this->load->helper('file_helper');
                $sql = read_file('application/sql/lf.sql');
                if($sql == FALSE) {
                        echo get_filenames('');
                        die ('file failed to read');
                }
                //echo $sql;
                //$this->db->query($sql);
                $segment = explode(";",trim($sql));
                $con = mysql_connect('localhost','root','root') or die('cannot connect to database');
                mysql_query($sql) or die('cannot query sql');



这是我现在的代码 每次都是cannot query sql
还想请教是否可以直接用CI的db直接执行呢

十分感谢

windwild 发表于 2012-2-16 16:54:27

http://codeigniter.org.cn/forums/thread-6626-1-1.html

刚刚看到这个帖子 尝试一下
页: [1]
查看完整版本: 如何执行sql文件呢