Jump to content

PDO - Erro


Diogo Guimaraes

Recommended Posts

Boas, 

Estava a fazer um ficheiro de funções e queria saber a razão por não consigo executar as querys da seguinte forma.

 

<?php

	function ligarDB(){
		
		$servidor 	= 'localhost';
		$utilizador = 'root';
		$password 	= '';
		$base_dados = 'teste';
		
		try{
			
			$ligar = new PDO("mysql:host=$servidor;dbname=$base_dados", $utilizador, $password);
			$ligar->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		}
		catch(PDOException $e){
			
			echo " Erro a ligar à base de dados";
		}
		
		return $ligar;
	}
	
	function inserirClientes($cliente, $password, $email){

		$ligar = ligarDB();							
		
		$pdo = $ligar->query("INSERT INTO `clientes`(`cliente`, `password`, `email`) VALUES ('$cliente','$password','$email')");
		if ($pdo){
			echo "inseridos";
		}else{
			echo "nao inseridos";
		}
		return 0;		
		
	}

inserirClientes('cliente_teste', 'password_teste', 'email@teste.pt');

?>

-----------

 

Edited by Diogo Guimaraes
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.