* @copyright 2010 Bartolomé Sintes Marco
* @license http://www.gnu.org/licenses/agpl.txt AGPL 3 or later
* @version 2010-04-20
* @link https://www.mclibre.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
define("MYSQL", "MySQL");
define("SQLITE", "SQLite");
define("TAM_FECHA", 10); // Tamaño del campo Fecha
define("MYSQL_HOST", "mysql:host=localhost"); // Nombre de host MYSQL
define("MYSQL_USER", "root"); // Nombre de usuario de MySQL
define("MYSQL_PASSWORD", ""); // Contraseña de usuario de MySQL
function conectaDb()
{
global $dbMotor, $dbDb;
try {
if ($dbMotor == MYSQL) {
$db = new PDO(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
$db->exec("set session sql_mode='ALLOW_INVALID_DATES'");
} elseif ($dbMotor == SQLITE) {
$db = new PDO("sqlite:$dbDb");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
$db->query("PRAGMA foreign_keys = ON");
$db->query("PRAGMA encoding = 'UTF-8'");
}
return $db;
} catch (PDOException $e) {
print "
Error: No puede conectarse con la base de datos.{$e->getMessage()}
\n";
print " \n";
}
}
function borraTodoMySQL($db)
{
global $dbDb, $dbTabla;
print "
Este programa prueba el amacenamiento de fechas en SQLite y MySQL
\n";
print "\n";
// Prueba con SQLite
print "
\n";
print "
\n";
print "
\n";
print "
SQLite
\n";
$dbMotor = SQLITE;
$dbDb = "/tmp/mclibre-db-diferencias.sqlite"; // Nombre de la base de datos
$dbTabla = "fecha"; // Nombre de la tabla
print " \n";
$db = conectaDb();
borraTodoSqlite($db);
pruebaDB();
print "
\n";
print "
\n";
// Prueba con MySQL
print "
MySQL
\n";
$dbMotor = MYSQL;
$dbDb = "mclibre_db_diferencias"; // Nombre de la base de datos
$dbTabla = $dbDb . ".fecha"; // Nombre de la tabla
print " \n";
$db = conectaDb();
if ($db) {
borraTodoMySQL($db);
pruebaDB();
}
print "