require('./connect.db.inc.php');
require("Console/Getopt.php");
-function check($sql, $commentaire='') {
- $res = mysql_query($sql);
- if ($err = mysql_error()) echo $err;
- if (mysql_num_rows($res)>0) {
+function check($sql, $commentaire='')
+{
+ $it = XDB::iterRow($sql);
+ if ($err = XDB::error()) echo $err;
+ if ($it->total() > 0) {
echo "Erreur pour la verification : $commentaire\n$sql\n\n";
echo "|";
- while($col = mysql_fetch_field($res)) echo "\t".$col->name."\t|";
+ while($col = $it->nextField()) {
+ echo "\t".$col->name."\t|";
+ }
echo "\n";
- while ($arr = mysql_fetch_row($res)) {
+ while ($arr = $it->next()) {
echo "|";
foreach ($arr as $val) echo "\t$val\t|";
echo "\n";
function query ($sql) {
XDB::execute($sql);
- if (mysql_errno() != 0) {
- echo "error in \"$sql\" :\n", mysql_error(),"\n";
+ if (XDB::errno() != 0) {
+ echo "error in \"$sql\" :\n", XDB::error(), "\n";
}
}
echo "\n\n";
$sql = "INSERT IGNORE INTO emails_watch (email, state, detection, last)
VALUES " . join(", ", $insert);
- Xdb::execute($sql);
- if (mysql_errno() != 0) {
- echo 'Error : ' . mysql_error() . "\n$sql";
+ XDB::execute($sql);
+ if (XDB::errno() != 0) {
+ echo 'Error : ' . XDB::error() . "\n$sql";
}
}
list($us, $ss) = explode(" ", $time_start);
$time = intval((($ue - $us) + ($se - $ss)) * 1000);
$trace_data['error'] = XDB::$mysqli->error;
+ $trace_data['errno'] = XDB::$mysqli->errno;
$trace_data['exectime'] = $time;
$trace_data['rows'] = @$res->num_rows ? $res->num_rows : XDB::$mysqli->affected_rows;
$GLOBALS['XDB::trace_data'][] = $trace_data;
return XDB::$mysqli->insert_id;
}
+ public static function errno()
+ {
+ global $globals;
+ if ($globals->debug & 1) {
+ $count = count($GLOBALS['XDB::trace_data']);
+ if (!$count) {
+ return 0;
+ }
+ return $GLOBALS['XDB::trace_data'][$count - 1]['errno'];
+ }
+ return XDB::$mysqli->errno;
+ }
+
+ public static function error()
+ {
+ global $globals;
+ if ($globals->debug & 1) {
+ $count = count($GLOBALS['XDB::trace_data']);
+ if (!$count) {
+ return null;
+ }
+ return $GLOBALS['XDB::trace_data'][$count - 1]['error'];
+ }
+ return XDB::$mysqli->error;
+ }
+
+ public static function affectedRows()
+ {
+ return XDB::$mysqli->affected_rows;
+ }
+
public static function _db_escape($var)
{
switch (gettype($var)) {
return $res;
}
+ function fetchOneField()
+ {
+ return $this->_res->fetch_field();
+ }
+
+ function fetchFields()
+ {
+ $res = array();
+ while ($res[] = $this->fetchOneField());
+ return $res;
+ }
+
function numRows()
{
return $this->_res->num_rows;
}
+
+ function fieldCount()
+ {
+ return $this->_res->field_count;
+ }
}
class XOrgDBIterator
private $_result;
private $_pos;
private $_total;
+ private $_fpos;
+ private $_fields;
private $_mode = MYSQL_ASSOC;
function __construct($query, $mode = MYSQL_ASSOC)
$this->_result = new XOrgDBResult($query);
$this->_pos = 0;
$this->_total = $this->_result->numRows();
+ $this->_fpost = 0;
+ $this->_fields = $this->_result->fieldCount();
$this->_mode = $mode;
}
function last()
{
- return $this->_last == $this->_total;
+ return $this->_pos == $this->_total;
}
function total()
{
return $this->_total;
}
+
+ function nextField()
+ {
+ $this->_fpos++;
+ if ($this->_fpos > $this->_fields) {
+ return null;
+ }
+ return $this->_result->fetchOneField();
+ }
+
+ function firstField()
+ {
+ return $this->_fpos == 1;
+ }
+
+ function lastField()
+ {
+ return $this->_fpos == $this->_fields;
+ }
+
+ function totalFields()
+ {
+ return $this->_fields;
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
XDB::execute('DELETE FROM watch_sub WHERE uid={?}', $this->_uid);
foreach (Env::v($ind) as $key=>$val) {
XDB::query('INSERT INTO watch_sub SELECT {?},id FROM watch_cat WHERE id={?}', $this->_uid, $key);
- if(mysql_affected_rows()) {
+ if(XDB::affectedRows()) {
$this->_data[$key] = $key;
}
}
#!/usr/bin/php5
<?php
+global $globals;
require_once 'connect.db.inc.php';
+$globals->dbcharset = 'latin1';
function is_utf8($s)
{
}
$tables = array ('city', 'city_in_maps', 'maps', 'pays', 'region');
-XDB::execute("SET NAMES 'latin1'");
foreach ($tables as $table) {
$res = XDB::query("SELECT * FROM geoloc_$table");
if (!$res) {
$from = array();
$to = array();
foreach ($array as $key=>$value) {
- $from[] = $key . '="' . mysql_real_escape_string($value) . '"';
+ $from[] = $key . '="' . XDB::_db_escape($value) . '"';
$valued = utf8_decode($value);
if (is_utf8($value) && $valued != $value) {
- $to[] = $key . '="' . mysql_real_escape_string($valued) .'"';
+ $to[] = $key . '="' . XDB::_db_escape($valued) .'"';
}
}
if (!empty($to)) {