I have a system which initially does it with PHP and MYSQL
I have migrated to SQL SERVER, and I am trying to configure it, I already downloaded and installed the dll's and referenced them in XAMMP in php.ini, however it throws me the following error when logging in
this is my connection file
<?php
class Cconexion{
function ConexionBD(){
$host='localhost';
$dbname='sistema_encuestasv1';
$username='DESKTOP-SIMP7PV\tulio';
$pasword ='';
$puerto=1433;
$con = new PDO ("sqlsrv:Server=$host,$puerto;Database=$dbname",$username,$pasword);
echo "Se conectó correctamen a la base de datos";
}
}
?>
and this is my validation.php file
<?php
session_start();
$id_usuario = $_POST['id_usuario'];
echo $id_usuario;
$clave = $_POST['clave'];
echo $clave;
include("conexion.php");
$query = "SELECT * FROM usuarios WHERE id_usuario = '$id_usuario' AND clave = '$clave'";
$resultado = $con->query($query);
if ($row = $resultado->fetch_assoc()) {
if ($row['id_tipo_usuario'] == '1') {
$_SESSION['id_usuario'] = $row['id_usuario'];
$_SESSION['u_usuario'] = $row['nombres'];
header("Location: administrador/index.php");
} else {
$_SESSION['id_usuario'] = $row['id_usuario'];
$_SESSION['u_usuario'] = $row['nombres'];
header("Location: usuario/index.php");
}
if ($row['id_tipo_usuario'] == '3') {
$_SESSION['id_usuario'] = $row['id_usuario'];
$_SESSION['u_usuario'] = $row['nombres'];
header("Location: usuario_vista/index.php");
}
} else {
header("Location: index.php");
}
if (!$query) {
printf("Error: %s\n", mysqli_error($conn));
exit();
}
?>
and these are my tables of the base after the migration
If someone can help me since this migration thing is totally new to me and I don't know if I missed something
I don't know where you get those examples or tutorials from, there are already two similar questions in a few days with the same problem.
You have two solutions at a glance:
This way, by doing your include, you're making the $con variable global and you can use it directly as you're already trying.
return $con;
to the end of the DBConnection function in the connection.php file so that, after including that connection.php file with an include in another file, it will properly call the class and function like so: