<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
include "config.php";
function catchErr($module, $err, $sql) {
$debug = true;
if (!$debug) {
sleep(1);
//emailNotify($module, $err, $sql);
} else {
die("$module: $err [SQL:$sql]");
}
}
function emailNotify($module, $msg, $sql) {
$email = "info@ivernahomes.es";
$to = "info@ivernahomes.es";
$now = date("d/m/Y H:i:s", time());
$subject = '[Iverna Email Notify] : ' . $module;
$msg = "Module: $module \r\nDateTime: $now \r\nMessege: $msg \r\nSQL: $sql \r\nSERVER:\r\n".print_r($_SERVER);
mail($to,
$subject,
$msg,
"From: $email\r\nReturn-Path: $email\r\n");
}
function dbConnect($module) {
//1. Crear conexi�n a la Base de Datos
$conexion = mysql_connect("localhost","root","musica2014");
if (!$conexion) {
die("Fallo la conexi�n a la Base de Datos: " . mysql_error());
}
//2. Seleccionar la Base de Datos a utilizar
$seleccionar_bd = mysql_select_db("iverna2_web", $conexion);
if (!$seleccionar_bd) {
die("Fallo la selecci�n de la Base de Datos: " . mysql_error());
}
mysql_close($conexion);
echo "Mensaje enviado exitosamente";
function dbClose($Conn) {
if ($Conn != null)
mysql_close($Conn) or catchErr("dbClose", mysql_error(), "");
return $Conn;
}
$Conn = null;
}
function dbExecute($sql, $module) {
$ret = false;
$result = mysql_query($sql) or catchErr($module, mysql_error(), $sql);
$ret = ($result != null);
return $ret;
}
function dbExecuteWithId($sql, $module) {
$lastid = 0;
$result = mysql_query($sql) or catchErr($module, mysql_error(), $sql);
if ($result != null) {
$lastid= mysql_insert_id();
}
return $lastid;
}
function dbQuery($sql, $module) {
$result = mysql_query($sql) or catchErr($module, mysql_error(), $sql);
if ($result != null)
return $result;
else
return null;
}
function dbFetchClose($result, $Conn) {
if ($result != null) {
mysql_free_result($result);
}
dbClose($Conn);
}
function dbFirstField($sql, $module) {
$return = "";
$result = mysql_query($sql) or catchErr($module, mysql_error(), $sql);
if ($result != null) {
$row = mysql_fetch_array($result, MYSQL_NUM);
$return = $row[0];
mysql_free_result($result);
}
return $return;
}
function dbIsExist($sql, $module) {
return (dbFirstField($sql, $module) == '1');
}
function dbLastId($module) {
return (dbFirstField("select LAST_INSERT_ID();", $module));
}
function dbCount($sqlfrom, $module) {
$sql = "select count(1) ".$sqlfrom;
return dbFirstField($sql, $module);
}
function dbLookup($id, $type, $module) {
global $lang;
if ($id == '') $id = 0;
$lkname = 'Lookupname';
$lkdescrp = 'Description';
if ($lang == 'en') {
$lkname = 'Lookupname2';
$lkdescrp = 'Description2';
} else if ($lang == 'de') {
$lkname = 'Lookupname1';
$lkdescrp = 'Description1';
}
$sql = "SELECT $lkname as name FROM lookup where Lookuptype = '$type' and Lookupvalue = $id and Obselute <> 1 ";
return dbFirstField($sql, $module);
}
function dbWriteOptions($sql, $module, $id) {
$result = mysql_query($sql) or catchErr($module, mysql_error(), $sql);
if ($result != null) {
while ($row = mysql_fetch_assoc($result)) {
echo "<option value='".$row['id']."'";
if ($row['id'] == $id)
echo " selected ";
echo ">".$row['name']."</option>";
}
mysql_free_result($result);
}
}
function dbParam($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "''";//"NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
function sToTime($s) {
return strtotime(str_replace("-", "/", $s));
}
function showText($s) {
return str_replace("\r\n","<br>", $s);
}
?>
el archivo config.php lo he modificado y de momento lo tengo asi, aunque me dice que conecta, la realidad es que no conecta pero he comprobado con una pequeña aplicacion que si se puede.
<?php
//1. Crear conexión a la Base de Datos
$conexion = mysql_connect("localhost","root","musica2014");
if (!$conexion) {
die("Fallo la conexión a la Base de Datos: " . mysql_error());
}
//2. Seleccionar la Base de Datos a utilizar
$seleccionar_bd = mysql_select_db("iverna2_web", $conexion);
if (!$seleccionar_bd) {
die("Fallo la selección de la Base de Datos: " . mysql_error());
}
mysql_close($conexion);
echo "Mensaje enviado exitosamente";
$allowexts = array('jpg','gif','jpeg','png') ;
$uploadpath = "upload/";
$dateformat_edit = '%d-%m-%Y';
$dateformat_longview = '%D %M %Y';
$dateformat_view = '%D %b %Y';
$admin_email = 'info@ivernahomes.es';
?>