if(count($res)>0){
if($overwrite){
$b=$this->update($table,$data,$q);
- print("update data: ".($b===false?"failed":"success")."<br>\n");
+ print("update data: ".($b===false?"failed":"success")."<br/>\n");
+ if($b===false)print("<font color=\"red\">Error: ".htmlentities($this->lastError())."</font><br/>\n");
}else{
print("ignoring existing row<br>\n");
}
}else{
$b=$this->insert($table,$data);
- print("insert data: ".($b===false?"failed":"success")."<br>\n");
+ print("insert data: ".($b===false?"failed":"success")."<br/>\n");
+ if($b===false)print("<font color=\"red\">Error: ".htmlentities($this->lastError())."</font><br/>\n");
}
}
print("Switching to table ".htmlspecialchars($table)."<br>\n");
break;
case "value":
+ if(!isset($cmd[3]))$cmd[3]='';
$data[$cmd[1]]=$this->unescapeBackup($cmd[2],$cmd[3]);
break;
case "insert":
private $dbname="";
private $engine="InnoDB";
private $charset="utf8";
+ private $collate="utf8_bin";
private $intrans=false;
//used for table creation to work around mysql bugs
private $tableappend;
$this->engine=$e;
}
- /**set the default charset for tables and connections*/
- public function setCharacterSet($c)
+ /**set the default charset and collation for tables and connections
+ \param cs the character set - like 'latin1' or 'utf8', this must be a charset supported by MySQL, the default is 'utf8'
+ \param col the collation to be used, the default is to use the corresponding binary collation (if you specify an empty string the default of MySQL will be used, which is a case independent comparison!)
+ */
+ public function setCharacterSet($cs,$col="%_bin")
{
- $this->charset=$c;
+ $this->charset=$cs;
+ $this->collate=str_replace('%',$cs,$col);
}
public function tryConnect()
die("Unable to connect to database system. Giving up.");
//select Unicode or whatever charset is configured
$cs=$this->escapeString($this->charset);
- if(mysqli_query($this->dbhdl,"SET NAMES ".$cs)===false)
- die("Cannot set DB character set to ".$cs.", aborting.");
+ $col=$this->escapeString($this->collate);
+ $q="SET NAMES ".$cs;
+ if($this->collate!="")$q.=" COLLATE ".$col;
+ if(mysqli_query($this->dbhdl,$q)===false)
+ die("Cannot set DB character set to ".$cs." and collation to ".$col.", aborting.");
//make sure the DB is transaction safe
if(mysqli_query($this->dbhdl,"SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE")===false)
die("Cannot make this database transaction safe, aborting");
{
$this->tableappend="";
$sql=parent::sqlCreateTable($tn,$t)." engine=".$this->engine." default charset=".$this->charset;
+ if($this->collate!="")$sql.=" collate=".$this->collate;
// print("<pre>\n$sql\n</pre>\n");
return $sql;
}