source: trunk/includes/dbimport.inc.php @ 782

Revision 782, 2.3 KB checked in by r2, 13 months ago (diff)

копирайты

  • Property svn:executable set to *
Line 
1<?php
2/******************************************************************************/
3//                                                                            //
4//                             InstantCMS v1.8                                //
5//                        http://www.instantcms.ru/                           //
6//                                                                            //
7//                   written by InstantCMS Team, 2007-2010                    //
8//                produced by InstantSoft, (www.instantsoft.ru)               //
9//                                                                            //
10//                        LICENSED BY GNU/GPL v2                              //
11//                                                                            //
12/******************************************************************************/
13
14        function runQuery($sql){
15                if ($sql){
16                        mysql_query(trim($sql)) or die(mysql_error().'<pre>'.$sql.'</pre>');
17                }
18        }
19
20        function dbRunSQL($sql_file, $db_pref){
21                if (file_exists($sql_file)){
22                                mysql_query("SET NAMES cp1251");
23                                $sqlfile = fopen($sql_file, 'r');                               
24                                $sql = '';                             
25                                while(!feof($sqlfile)){
26                                        $str = fgets($sqlfile);
27                                        $str = str_replace("#_", $db_pref, $str);
28                                        if(!preg_match('/^\-\-(.*)$/i', $str)) {
29                                                if (   strstr($str, 'SET ') ||
30                                strstr($str, 'CREATE TABLE') ||
31                                strstr($str, 'INSERT INTO') ||
32                                strstr($str, 'DROP') ||
33                                strstr($str, 'UPDATE') ||
34                                strstr($str, 'ALTER TABLE')){
35
36                            if ($sql){
37                                $sql = str_replace("DEFAULT 'CURRENT_TIMESTAMP'", "DEFAULT CURRENT_TIMESTAMP", $sql);
38                                mysql_query($sql) or die(mysql_error().'<pre>'.$sql.'</pre>');
39                            }
40
41                            $sql = $str;
42                           
43                                                } else {
44                                                        $sql .= $str;
45                                                }
46                                        }
47                                }
48                                if ($sql!=''){
49                                        mysql_query($sql) or die(mysql_error().'<pre>'.$sql.'</pre>');
50                                }
51                                if(!mysql_error()){
52                                        return true;
53                                } else { return false; }
54                }               
55        }
56       
57?>
Note: See TracBrowser for help on using the repository browser.