Haciendo el curso 3 he tenido problemas con pasar de mysql a mysqli y gracias a zeus conseguí resolverlo.
Os dejo los archivos viejos comparados con los nuevos para que se vea como debe quedar.
la conexion.php antes:
la conexion.php con mysqli:
funciones.php con mysqli :
Editado
Os dejo los archivos viejos comparados con los nuevos para que se vea como debe quedar.
la conexion.php antes:
<?php
if (!isset($_SESSION)) {
session_start();
}
$hostname_conexion = "";
$database_conexion = "";
$username_conexion = "";
$password_conexion = "";
$conexion = mysql_conect($hostname_conexion, $username_conexion, $password_conexion) or trigger_error(mysql_error(),E_USER_ERROR);
?>la conexion.php con mysqli:
<?php
if (!isset($_SESSION)) {
session_start();
}
//CONEXIÓN A LA BASE DE DATOS
$hostname_db = "";
$database_conexion = "";
$username_db = "";
$password_db = "";
//Conectar a la base de datos
$conexion = mysqli_connect($hostname_db, $username_db, $password_db);
//Seleccionar la base de datos
mysqli_select_db($conexion,$database_conexion) or die ("Ninguna DB seleccionada");
?>antes login.php : mysql_select_db($database_conexion, $conexion);
$query_DatosWeb = sprintf("SELECT * FROM z_user WHERE user=%s AND password=%s",
GetSQLValueString($_POST['user'], "text"),
GetSQLValueString($_POST['pass'], "text")
);
$DatosWeb = mysql_query($query_DatosWeb, $conexion) or die(mysql_error());
$row_DatosWeb = mysql_fetch_assoc($DatosWeb);
$totalRows_DatosWeb = mysql_num_rows($DatosWeb);
if ($totalRows_DatosWeb==1) {
$_SESSION['iduser']=$row_DatosWeb['id'];
$_SESSION['nombreuser']=$row_DatosWeb['user'];
}
mysql_free_result($DatosWeb);
?>login.php con mysqli : mysqli_select_db($conexion, $database_conexion);
$query_DatosWeb = sprintf("SELECT * FROM z_user WHERE user=%s AND password=%s",
GetSQLValueString($_POST['user'], "text"),
GetSQLValueString($_POST['pass'], "text")
);
$DatosWeb = mysqli_query($conexion, $query_DatosWeb) or die(mysqli_error());
$row_DatosWeb = mysqli_fetch_assoc($DatosWeb);
$totalRows_DatosWeb = mysqli_num_rows($DatosWeb);
if ($totalRows_DatosWeb==1) {
$_SESSION['iduser']=$row_DatosWeb['id'];
$_SESSION['nombreuser']=$row_DatosWeb['user'];
}
mysqli_free_result($DatosWeb);
?>funciones.php antes:<?php //Formateo Base de datos
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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;
}
}
?>funciones.php con mysqli :
<?php //Formateo Base de datos
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
global $conexion;
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($conexion, $theValue) : mysqli_escape_string($conexion, $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;
}
}
?>Editado
5
Puntos
Puntos
2600
Visitas
Visitas
0
Resp
Resp
Por 00katalin00 hace 9 años
Novice