mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-16 06:21:28 +01:00
299 lines
15 KiB
HTML
299 lines
15 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|
<title>dolibarr: htdocs/lib/mysql.lib.php Source File</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head><body>
|
|
<!-- Généré par Doxygen 1.3.7 -->
|
|
<div class="qindex"><a class="qindex" href="index.html">Page principale</a> | <a class="qindex" href="classes.html">Liste alphabétique</a> | <a class="qindex" href="annotated.html">Liste des classes</a> | <a class="qindex" href="files.html">Liste des fichiers</a> | <a class="qindex" href="functions.html">Membres de classe</a> | <a class="qindex" href="globals.html">Membres de fichier</a></div>
|
|
<h1>htdocs/lib/mysql.lib.php</h1><a href="mysql_8lib_8php.html">Aller à la documentation de ce fichier.</a><pre class="fragment"><div>00001 <?PHP
|
|
00002 <span class="comment">/* Copyright (C) 2001 Fabien Seisen <seisen@linuxfr.org></span>
|
|
00003 <span class="comment"> * Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org></span>
|
|
00004 <span class="comment"> * Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net></span>
|
|
00005 <span class="comment"> *</span>
|
|
00006 <span class="comment"> * $Id$</span>
|
|
00007 <span class="comment"> * $Source$</span>
|
|
00008 <span class="comment"> *</span>
|
|
00009 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
|
|
00010 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
|
|
00011 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
|
|
00012 <span class="comment"> * (at your option) any later version.</span>
|
|
00013 <span class="comment"> *</span>
|
|
00014 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
|
|
00015 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
|
00016 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
|
00017 <span class="comment"> * GNU General Public License for more details.</span>
|
|
00018 <span class="comment"> *</span>
|
|
00019 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
|
|
00020 <span class="comment"> * along with this program; if not, write to the Free Software</span>
|
|
00021 <span class="comment"> * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span>
|
|
00022 <span class="comment"> *</span>
|
|
00023 <span class="comment"> */</span>
|
|
00024
|
|
<a name="l00041"></a><a class="code" href="classDoliDb.html">00041</a> <span class="keyword">class </span><a class="code" href="classDoliDb.html">DoliDb</a> {
|
|
00042 var $db, $results, $ok, $connected, $database_selected;
|
|
00043
|
|
00044 <span class="comment">// Constantes pour code erreurs</span>
|
|
00045 var $ERROR_DUPLICATE=1062;
|
|
00046 var $ERROR_TABLEEXISTS=1050;
|
|
00047
|
|
<a name="l00057"></a><a class="code" href="classDoliDb.html#a0">00057</a> function <a class="code" href="classDoliDb.html">DoliDb</a>($type = 'mysql', $host = '', $user = '', $pass = '', $name = '')
|
|
00058
|
|
00059 <span class="comment">// Se connecte au serveur et éventuellement à une base (si spécifié)</span>
|
|
00060 <span class="comment">// Renvoie 1 en cas de succès, 0 sinon</span>
|
|
00061
|
|
00062 {
|
|
00063 global $conf;
|
|
00064
|
|
00065 <span class="keywordflow">if</span> ($host == '')
|
|
00066 {
|
|
00067 $host = $conf->db->host;
|
|
00068 }
|
|
00069
|
|
00070 <span class="keywordflow">if</span> ($user == '')
|
|
00071 {
|
|
00072 $user = $conf->db->user;
|
|
00073 }
|
|
00074
|
|
00075 <span class="keywordflow">if</span> ($pass == '')
|
|
00076 {
|
|
00077 $pass = $conf->db->pass;
|
|
00078 }
|
|
00079
|
|
00080 <span class="keywordflow">if</span> ($name == '')
|
|
00081 {
|
|
00082 $name = $conf->db->name;
|
|
00083 }
|
|
00084
|
|
00085 <span class="comment">//print "Name DB: $host,$user,$pass,$name<br>";</span>
|
|
00086
|
|
00087 <span class="comment">// Essai connexion serveur</span>
|
|
00088
|
|
00089 $this->db = $this-><a class="code" href="classDoliDb.html#a2">connect</a>($host, $user, $pass);
|
|
00090
|
|
00091 <span class="keywordflow">if</span> ($this->db)
|
|
00092 {
|
|
00093 $this->connected = 1;
|
|
00094 $this->ok = 1;
|
|
00095 }
|
|
00096 <span class="keywordflow">else</span>
|
|
00097 {
|
|
00098 $this->connected = 0;
|
|
00099 $this->ok = 0;
|
|
00100 }
|
|
00101
|
|
00102 <span class="comment">// Si connexion serveur ok et si connexion base demandée, on essaie connexion base</span>
|
|
00103
|
|
00104 <span class="keywordflow">if</span> ($this->connected && $name)
|
|
00105 {
|
|
00106
|
|
00107 <span class="keywordflow">if</span> ($this-><a class="code" href="classDoliDb.html#a1">select_db</a>($name) == 1)
|
|
00108 {
|
|
00109 $this->database_selected = 1;
|
|
00110 $this->ok = 1;
|
|
00111 }
|
|
00112 <span class="keywordflow">else</span>
|
|
00113 {
|
|
00114 $this->database_selected = 0;
|
|
00115 $this->ok = 0;
|
|
00116 }
|
|
00117
|
|
00118 }
|
|
00119 <span class="keywordflow">else</span>
|
|
00120 {
|
|
00121 <span class="comment">// Pas de selection de base demandée, mais tout est ok</span>
|
|
00122
|
|
00123 $this->database_selected = 0;
|
|
00124 $this->ok = 1;
|
|
00125 }
|
|
00126
|
|
00127 <span class="keywordflow">return</span> $this->ok;
|
|
00128 }
|
|
00129
|
|
<a name="l00136"></a><a class="code" href="classDoliDb.html#a1">00136</a> function <a class="code" href="classDoliDb.html#a1">select_db</a>($database)
|
|
00137 {
|
|
00138 <span class="keywordflow">return</span> mysql_select_db($database, $this->db);
|
|
00139 }
|
|
00140
|
|
<a name="l00149"></a><a class="code" href="classDoliDb.html#a2">00149</a> function <a class="code" href="classDoliDb.html#a2">connect</a>($host, $login, $passwd)
|
|
00150 {
|
|
00151 $this->db = @mysql_connect($host, $login, $passwd);
|
|
00152 <span class="comment">//print "Resultat fonction connect: ".$this->db;</span>
|
|
00153 <span class="keywordflow">return</span> $this->db;
|
|
00154 }
|
|
00155
|
|
<a name="l00162"></a><a class="code" href="classDoliDb.html#a3">00162</a> function <a class="code" href="classDoliDb.html#a3">create_db</a>($database)
|
|
00163 {
|
|
00164 <span class="keywordflow">if</span> (mysql_create_db ($database, $this->db))
|
|
00165 {
|
|
00166 <span class="keywordflow">return</span> 1;
|
|
00167 }
|
|
00168 <span class="keywordflow">else</span>
|
|
00169 {
|
|
00170 <span class="keywordflow">return</span> 0;
|
|
00171 }
|
|
00172 }
|
|
00173
|
|
<a name="l00179"></a><a class="code" href="classDoliDb.html#a4">00179</a> function <a class="code" href="classDoliDb.html#a4">clone</a>()
|
|
00180 {
|
|
00181 $db2 = <span class="keyword">new</span> DoliDb(<span class="stringliteral">""</span>, <span class="stringliteral">""</span>, <span class="stringliteral">""</span>, <span class="stringliteral">""</span>, <span class="stringliteral">""</span>);
|
|
00182 $db2->db = $this->db;
|
|
00183 <span class="keywordflow">return</span> $db2;
|
|
00184 }
|
|
00185
|
|
<a name="l00194"></a><a class="code" href="classDoliDb.html#a5">00194</a> function <a class="code" href="classDoliDb.html#a5">pconnect</a>($host, $login, $passwd)
|
|
00195 {
|
|
00196 $this->db = mysql_pconnect($host, $login, $passwd);
|
|
00197 <span class="keywordflow">return</span> $this->db;
|
|
00198 }
|
|
00199
|
|
<a name="l00205"></a><a class="code" href="classDoliDb.html#a6">00205</a> function <a class="code" href="classDoliDb.html#a6">close</a>()
|
|
00206 {
|
|
00207 <span class="keywordflow">return</span> mysql_close($this->db);
|
|
00208 }
|
|
00209
|
|
<a name="l00216"></a><a class="code" href="classDoliDb.html#a7">00216</a> function <a class="code" href="classDoliDb.html#a7">begin</a>($<span class="keywordflow">do</span>=1)
|
|
00217 {
|
|
00218 <span class="keywordflow">if</span> ($do)
|
|
00219 {
|
|
00220 <span class="keywordflow">return</span> $this-><a class="code" href="classDoliDb.html#a10">query</a>(<span class="stringliteral">"BEGIN"</span>);
|
|
00221 }
|
|
00222 <span class="keywordflow">else</span>
|
|
00223 {
|
|
00224 <span class="keywordflow">return</span> 1;
|
|
00225 }
|
|
00226 }
|
|
00227
|
|
<a name="l00234"></a><a class="code" href="classDoliDb.html#a8">00234</a> function <a class="code" href="classDoliDb.html#a8">commit</a>($<span class="keywordflow">do</span>=1)
|
|
00235 {
|
|
00236 <span class="keywordflow">if</span> ($do)
|
|
00237 {
|
|
00238 <span class="keywordflow">return</span> $this-><a class="code" href="classDoliDb.html#a10">query</a>(<span class="stringliteral">"COMMIT"</span>);
|
|
00239 }
|
|
00240 <span class="keywordflow">else</span>
|
|
00241 {
|
|
00242 <span class="keywordflow">return</span> 1;
|
|
00243 }
|
|
00244 }
|
|
00245
|
|
<a name="l00252"></a><a class="code" href="classDoliDb.html#a9">00252</a> function <a class="code" href="classDoliDb.html#a9">rollback</a>($<span class="keywordflow">do</span>=1)
|
|
00253 {
|
|
00254 <span class="keywordflow">if</span> ($do)
|
|
00255 {
|
|
00256 <span class="keywordflow">return</span> $this-><a class="code" href="classDoliDb.html#a10">query</a>(<span class="stringliteral">"ROLLBACK"</span>);
|
|
00257 }
|
|
00258 <span class="keywordflow">else</span>
|
|
00259 {
|
|
00260 <span class="keywordflow">return</span> 1;
|
|
00261 }
|
|
00262 }
|
|
00263
|
|
<a name="l00272"></a><a class="code" href="classDoliDb.html#a10">00272</a> function <a class="code" href="classDoliDb.html#a10">query</a>($query, $limit=<span class="stringliteral">""</span>, $offset=<span class="stringliteral">""</span>)
|
|
00273 {
|
|
00274 $query = trim($query);
|
|
00275 <span class="comment">//print "<p>$query</p>\n";</span>
|
|
00276 $this->results = mysql_query($query, $this->db);
|
|
00277 <span class="keywordflow">return</span> $this->results;
|
|
00278 }
|
|
00279
|
|
<a name="l00286"></a><a class="code" href="classDoliDb.html#a11">00286</a> function <a class="code" href="classDoliDb.html#a11">list_tables</a>($database)
|
|
00287 {
|
|
00288 $this->results = mysql_list_tables($database, $this->db);
|
|
00289 <span class="keywordflow">return</span> $this->results;
|
|
00290 }
|
|
00291
|
|
<a name="l00299"></a><a class="code" href="classDoliDb.html#a12">00299</a> function <a class="code" href="classDoliDb.html#a12">result</a>($nb, $fieldname)
|
|
00300 {
|
|
00301 <span class="keywordflow">return</span> mysql_result($this->results, $nb, $fieldname);
|
|
00302 }
|
|
00303
|
|
<a name="l00309"></a><a class="code" href="classDoliDb.html#a13">00309</a> function <a class="code" href="classDoliDb.html#a13">free</a>()
|
|
00310 {
|
|
00311 <span class="keywordflow">return</span> mysql_free_result($this->results);
|
|
00312 }
|
|
00313
|
|
<a name="l00319"></a><a class="code" href="classDoliDb.html#a14">00319</a> function <a class="code" href="classDoliDb.html#a14">fetch_object</a>()
|
|
00320 {
|
|
00321 <span class="keywordflow">return</span> mysql_fetch_object($this->results);
|
|
00322 }
|
|
00323
|
|
<a name="l00331"></a><a class="code" href="classDoliDb.html#a15">00331</a> function <a class="code" href="classDoliDb.html#a15">plimit</a>($limit=0,$offset=0)
|
|
00332 {
|
|
00333 <span class="keywordflow">if</span> ($offset > 0)
|
|
00334 {
|
|
00335 <span class="keywordflow">return</span> <span class="stringliteral">" LIMIT $offset,$limit "</span>;
|
|
00336 }
|
|
00337 <span class="keywordflow">else</span>
|
|
00338 {
|
|
00339 <span class="keywordflow">return</span> <span class="stringliteral">" LIMIT $limit "</span>;
|
|
00340 }
|
|
00341 }
|
|
00342
|
|
00343
|
|
00344 function pdate($fname)
|
|
00345 {
|
|
00346 <span class="keywordflow">return</span> <span class="stringliteral">"unix_timestamp($fname)"</span>;
|
|
00347 }
|
|
00348
|
|
<a name="l00355"></a><a class="code" href="classDoliDb.html#a17">00355</a> function <a class="code" href="classDoliDb.html#a17">idate</a>($fname)
|
|
00356 {
|
|
00357 <span class="keywordflow">return</span> strftime(<span class="stringliteral">"%Y%m%d%H%M%S"</span>,$fname);
|
|
00358 }
|
|
00359
|
|
<a name="l00365"></a><a class="code" href="classDoliDb.html#a18">00365</a> function <a class="code" href="classDoliDb.html#a18">fetch_array</a>()
|
|
00366 {
|
|
00367 <span class="keywordflow">return</span> mysql_fetch_array($this->results);
|
|
00368 }
|
|
00369
|
|
<a name="l00375"></a><a class="code" href="classDoliDb.html#a19">00375</a> function <a class="code" href="classDoliDb.html#a19">fetch_row</a>()
|
|
00376 {
|
|
00377 <span class="keywordflow">return</span> mysql_fetch_row($this->results);
|
|
00378 }
|
|
00379
|
|
<a name="l00384"></a><a class="code" href="classDoliDb.html#a20">00384</a> function <a class="code" href="classDoliDb.html#a20">fetch_field</a>()
|
|
00385 {
|
|
00386 <span class="keywordflow">return</span> mysql_fetch_field($this->results);
|
|
00387 }
|
|
00388
|
|
00389
|
|
<a name="l00395"></a><a class="code" href="classDoliDb.html#a21">00395</a> function <a class="code" href="classDoliDb.html#a21">num_rows</a>()
|
|
00396 {
|
|
00397 <span class="keywordflow">return</span> mysql_num_rows($this->results);
|
|
00398 }
|
|
00399
|
|
<a name="l00405"></a><a class="code" href="classDoliDb.html#a22">00405</a> function <a class="code" href="classDoliDb.html#a22">num_fields</a>()
|
|
00406 {
|
|
00407 <span class="keywordflow">return</span> mysql_num_fields($this->results);
|
|
00408 }
|
|
00409
|
|
<a name="l00415"></a><a class="code" href="classDoliDb.html#a23">00415</a> function <a class="code" href="classDoliDb.html#a23">error</a>()
|
|
00416 {
|
|
00417 <span class="keywordflow">return</span> mysql_error($this->db);
|
|
00418 }
|
|
00419
|
|
<a name="l00425"></a><a class="code" href="classDoliDb.html#a24">00425</a> function <a class="code" href="classDoliDb.html#a24">errno</a>()
|
|
00426 {
|
|
00427 <span class="comment">// $ERROR_DUPLICATE=1062;</span>
|
|
00428 <span class="comment">// $ERROR_TABLEEXISTS=1050;</span>
|
|
00429
|
|
00430 <span class="keywordflow">return</span> mysql_errno($this->db);
|
|
00431 }
|
|
00432
|
|
<a name="l00438"></a><a class="code" href="classDoliDb.html#a25">00438</a> function <a class="code" href="classDoliDb.html#a25">last_insert_id</a>()
|
|
00439 {
|
|
00440 <span class="keywordflow">return</span> mysql_insert_id();
|
|
00441 }
|
|
00442
|
|
<a name="l00448"></a><a class="code" href="classDoliDb.html#a26">00448</a> function <a class="code" href="classDoliDb.html#a26">affected_rows</a>()
|
|
00449 {
|
|
00450 <span class="keywordflow">return</span> mysql_affected_rows();
|
|
00451 }
|
|
00452
|
|
00453 }
|
|
00454
|
|
00455 ?>
|
|
</div></pre><hr size="1"><address style="align: right;"><small>Généré le Fri Jul 16 00:31:07 2004 pour dolibarr par
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address>
|
|
</body>
|
|
</html>
|