Diogo Guimaraes Posted April 28, 2017 at 09:22 AM Report Share #603830 Posted April 28, 2017 at 09:22 AM (edited) 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 April 28, 2017 at 09:24 AM by Diogo Guimaraes Link to comment Share on other sites More sharing options...
Diogo Guimaraes Posted April 28, 2017 at 09:24 AM Author Report Share #603831 Posted April 28, 2017 at 09:24 AM Desculpem....já descobri, precisava de retornar a var $ligar da primeira função. Link to comment Share on other sites More sharing options...
devgoncalo Posted April 28, 2017 at 04:49 PM Report Share #603853 Posted April 28, 2017 at 04:49 PM ola o código como está apresenta falhas de segurança. sugiro que leias o seguinte texto: http://www.phptherightway.com/#databases cumps Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now