Merge branch '164-crash-on-patching-and-possibly-right-after-login' into 'main/atys...
[ryzomcore.git] / nelns / admin / public_html / sql_connection.php
blob807b61b209c88cbe0bf9219029fb8e1a4235a9c5
1 <?php
2 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
3 // Copyright (C) 2010 Winch Gate Property Limited
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 include('../config.php');
20 // connect to database
21 function connectToDatabase($dbhost, $dbname, $dblogin, $dbpasswd)
23 if (!mysql_connect($dbhost, $dblogin, $dbpasswd))
24 return "Unable to connect to MySQL server (host='$dbhost' login='$dblogin')";
25 if (!mysql_select_db ($dbname))
26 return "Unable to select MySQL database '$dbname'";
27 return FALSE;
30 // default connection to database
31 function defaultConnectToDatabase()
33 global $dbhost, $dbname, $dblogin, $dbpassword;
34 return connectToDatabase($dbhost, $dbname, $dblogin, $dbpassword);
37 function sqlquery($query)
39 // here log queries
40 global $sqlQueries;
41 $res = mysql_query($query);
42 $sqlQueries[] = $query.(($res)?"":" ***FAILED***: ".mysql_error());
43 return $res;
46 function sqlfetch(&$result)
48 return mysql_fetch_array($result);
51 function sqlnumrows(&$result)
53 return mysql_num_rows($result);
56 function sqlchrows(&$result)
58 return mysql_affected_rows($result);
61 function displayQueries()
63 global $sqlQueries;
64 if (isset($sqlQueries))
66 echo "<br><br><hr><ul>";
67 foreach ($sqlQueries as $query)
68 echo "<li>$query</li>\n";
69 echo "</ul>";
71 echo "<br><br><p align=right><textarea rows=15 cols=100 readOnly>";
72 foreach ($sqlQueries as $query)
73 echo "$query\n---\n";
74 echo "</textarea>\n";
79 if ($queries)
81 echo "<textarea rows=15 cols=100 readOnly>";
82 echo "$queries";
83 echo "</textarea>\n";
84 die();