YAP  2.5
 All Data Structures Namespaces Files Functions Variables
CYap_Mysql.php
Go to the documentation of this file.
1 <?PHP
10 /*
11  * +-------------------------------------------------------------------------+
12  * | Yap, Version 2.5.0 |
13  * +-------------------------------------------------------------------------+
14  * | Copyright (c) 2003-2013 Andrioli Darvin |
15  * | Email <darvin (inside) andrioli (dot) com> |
16  * | Web http://www.andrioli.com/en/yap.html |
17  * | Download http://www.phpclasses.org/browse.html/package/1391.html |
18  * | |
19  * +-------------------------------------------------------------------------+
20  * | This library is free software; you can redistribute it and/or modify |
21  * | it under the terms of the GNU Lesser General Public License as |
22  * | published by the Free Software Foundation; either version 2 of the |
23  * | License, or (at your option) any later version. |
24  * | |
25  * | This library is distributed in the hope that it will be useful, but |
26  * | WITHOUT ANY WARRANTY; without even the implied warranty of |
27  * | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
28  * | Lesser General Public License for more details. |
29  * | |
30  * | You should have received a copy of the GNU Lesser General Public |
31  * | License along with this library; if not, write to the Free Software |
32  * | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
33  * +-------------------------------------------------------------------------+
34  */
38 class CYap_mysql extends CYapDB {
39 
40 function CYap_mysql()
41 {
43 }
51 function OpenDb($DBSystem,$DBUser="",$DBPasswd="")
52 {
53 if($this->Db_Open)
54  {
55  $this->txtError='Database already open';
56  return(false);
57  }
58 if(($this->DbConn=mysql_connect($DBSystem,$DBUser,$DBPasswd))===FALSE)
59  {
60  // Errore di select del db
61  $this->txtError="Error during connection to the server ".$DBSystem;
62  return(false);
63  }
64 $this->Db_Open=true;
65 return(true);
66 }
72 function SelectDb($DBname)
73 {
74 if(!$this->Db_Open)
75  {
76  $this->txtError='No database open';
77  return(false);
78  }
79 if(!mysql_select_db($DBname,$this->DbConn))
80  {
81  // Errore di select del db
82  $this->txtError="I cannot select the db ".$DBname;
83  return(false);
84  }
85 return(true);
86 }
92 function DbExecSql($sql)
93 {
94 if(!$this->Db_Open)
95  {
96  $this->txtError='No database open';
97  return(false);
98  }
99 if(($this->DbResult=mysql_query($sql))===FALSE)
100  {
101  // Errore di select del db
102  $this->txtError="Error into sql statement. Sql string: ".$sql.".Err:". mysql_errno() . ": " . mysql_error();
103  return(false);
104  }
105 return($this->DbResult);
106 }
115 function QueryLimit($select,$start=0,$many=-1)
116 {
117 $sql=$select. " limit ".$start;
118 if($many!=-1)
119  $sql.=",".$many;
120 return($this->DbExecSql($sql));
121 }
127 function DbGetNumRow($result)
128 {
129 return(mysql_num_rows($result));
130 }
136 function DbGetNumFields($result)
137 {
138 return(mysql_num_fields($result));
139 }
147 function DbFetchField($result,$FieldNo)
148 {
149 return(mysql_fetch_field($result));
150 }
157 function DbFieldFlags($result,$FieldNo)
158 {
159 return(mysql_field_flags($result,$FieldNo));
160 }
166 function DbFreeResult($result)
167 {
168 if(!($es=mysql_free_result($result)))
169  $this->txtError=mysql_error();
170 return($es);
171 }
177 function DbGetValue($result)
178 {
179 if(!$this->Db_Open)
180  {
181  $this->txtError='No database open';
182  return(false);
183  }
184 return(mysql_fetch_array($result,MYSQL_ASSOC));
185 }
190 function Db_Close()
191 {
192 if(!$this->Db_Open)
193  {
194  $this->txtError='No database open';
195  return(false);
196  }
197 mysql_close($this->DbConn);
198 $this->Db_Open=false;
199 return(true);
200 }
209 function DbEscape($value)
210 {
211 $quote=(bool)ini_get('magic_quotes_gpc');
212 if(!$quote)
213  $ret=mysql_real_escape_string($value);
214 else
215  $ret=$value;
216 return($ret);
217 }
226 function DbRegexCond($FieldName,$pattern)
227 {
228 return($FieldName.' regexp \''.$pattern.'\'');
229 }
239 function DbBetweenCond($FieldName,$ValueFrom,$ValueTo,$ValueType)
240 {
241 if($ValueType=='DB_NUMBER')
242  return($FieldName.' between '.$ValueFrom.' and '.$ValueTo);
243 else
244  return($FieldName.' between \''.$ValueFrom.'\' and \''.$ValueTo.'\'');
245 }
246 }
247  ?>