3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2009 iDB Support - http://idb.berlios.de/
12 Copyright 2004-2009 Game Maker 2k - http://gamemaker2k.org/
14 $FileInfo: mysql.php - Last Update: 10/14/2010 SVN 588 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name=="mysql.php"||
$File3Name=="/mysql.php") {
18 @header
('Location: index.php');
21 function sql_error($link=null) {
23 $result = mysql_error($link); }
25 $result = mysql_error(); }
29 function sql_errno($link=null) {
31 $result = mysql_errno($link); }
33 $result = mysql_errno(); }
37 function sql_errorno($link=null) {
39 $result = sql_error($link);
40 $resultno = sql_errno($link); }
42 $result = sql_error();
43 $resultno = sql_errno(); }
44 if ($result==""&&$result===0) {
46 if ($result!=""&&$result!==0) {
47 $result = $resultno.": ".$result; }
51 function sql_query($query,$link=null) {
54 $result = mysql_query($query,$link); }
56 $result = mysql_query($query); }
57 if ($result===false) {
58 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
60 if ($result!==false) {
63 //Fetch Number of Rows
64 function sql_num_rows($result) {
65 $num = mysql_num_rows($result);
67 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
70 // Connect to mysql database
71 function sql_connect_db($server,$username,$password,$database=null,$new_link=false) {
72 if($new_link!==true) { $new_link = false; }
73 if($new_link!==true||
$new_link===false) {
74 $link = mysql_connect($server,$username,$password); }
75 if($new_link===true) {
76 $link = mysql_connect($server,$username,$password,$new_link); }
78 output_error("Not connected: ".sql_error(),E_USER_ERROR
);
80 if($database!==null) {
81 $dlink = mysql_select_db($database,$link);
83 output_error("Can't use database ".$database.": ".sql_error(),E_USER_ERROR
);
85 $result = sql_query("SET SESSION SQL_MODE='ANSI_QUOTES,NO_AUTO_VALUE_ON_ZERO';",$link);
86 if ($result===false) {
87 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
91 function sql_result($result,$row,$field=0) {
92 $value = mysql_result($result, $row, $field);
94 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
98 function sql_free_result($result) {
99 $fresult = mysql_free_result($result);
100 if ($fresult===false) {
101 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
103 if ($fresult===true) {
105 //Fetch Results to Array
106 function sql_fetch_array($result,$result_type=MYSQL_BOTH
) {
107 $row = mysql_fetch_array($result,$result_type);
109 //Fetch Results to Associative Array
110 function sql_fetch_assoc($result) {
111 $row = mysql_fetch_assoc($result);
114 function sql_fetch_row($result) {
115 $row = mysql_fetch_row($result);
118 function sql_server_info($link=null) {
120 $result = mysql_get_server_info($link); }
122 $result = mysql_get_server_info(); }
125 function sql_client_info($link=null) {
126 $result = mysql_get_client_info();
128 function sql_escape_string($string,$link=null) {
130 $string = mysql_real_escape_string($string,$link); }
132 $string = mysql_real_escape_string($string); }
133 if ($string===false) {
134 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
137 // SafeSQL Lite Source Code by Cool Dude 2k
138 // Make SQL Query's safe
139 function sql_pre_query($query_string,$query_vars) {
140 $query_array = array(array("%i","%I","%F","%S"),array("%d","%d","%f","%s"));
141 $query_string = str_replace($query_array[0], $query_array[1], $query_string);
142 if (get_magic_quotes_gpc()) {
143 $query_vars = array_map("stripslashes", $query_vars); }
144 $query_vars = array_map("sql_escape_string", $query_vars);
145 $query_val = $query_vars;
146 $query_num = count($query_val);
148 while ($query_i < $query_num) {
149 $query_is = $query_i+
1;
150 $query_val[$query_is] = $query_vars[$query_i];
152 $query_val[0] = $query_string;
153 return call_user_func_array("sprintf",$query_val); }
154 function sql_set_charset($charset,$link=null) {
155 if(function_exists('mysql_set_charset')===false) {
157 $result = sql_query("SET CHARACTER SET '".$charset."'"); }
159 $result = sql_query("SET CHARACTER SET '".$charset."'",$link); }
160 if ($result===false) {
161 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
164 $result = sql_query("SET NAMES '".$charset."'"); }
166 $result = sql_query("SET NAMES '".$charset."'",$link); }
167 if ($result===false) {
168 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
171 if(function_exists('mysql_set_charset')===true) {
173 $result = mysql_set_charset($charset,$link); }
175 $result = mysql_set_charset($charset); }
176 if ($result===false) {
177 output_error("SQL Error: ".sql_error(),E_USER_ERROR
);
181 if(function_exists('mysql_set_charset')===false) {
182 function mysql_set_charset($charset,$link) {
184 $result = sql_set_charset($charset,$link); }
186 $result = sql_set_charset($charset); }
187 if ($result===false) {
188 output_error("SQL Error: ".sql_error(),E_USER_ERROR);
192 // Get next id for stuff
193 function sql_get_next_id($tablepre,$table,$link=null) {
194 $nid = mysql_insert_id($link);
196 // Get number of rows for table
197 function sql_get_num_rows($tablepre,$table,$link=null) {
198 $getnextidq = sql_pre_query("SHOW TABLE STATUS LIKE '".$tablepre.$table."'", array());
200 $getnextidr = sql_query($getnextidq); }
202 $getnextidr = sql_query($getnextidq,$link); }
203 $getnextid = sql_fetch_assoc($getnextidr);
204 return $getnextid['Rows'];
205 @sql_free_result
($getnextidr); }