Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. class Conexion {
  4.  
  5. function Conectar(){
  6. try{
  7. $servidor = "localhost";
  8. $user = "root";
  9. $pass = "";
  10. $db = "bdejemplos";
  11. $con = new PDO("mysql:host=$servidor;dbname=$db",$user,$pass);
  12. echo 'conectado';
  13.  
  14. } catch (Exception $e){
  15. echo 'Error '. $e->getMessage();
  16. }
  17. return $con;
  18. }
  19. }
  20.  
  21. ?>
  22.  
  23. ***OpClientes.php***
  24. <?php
  25. include './Conexion.php';
  26. //include_once '../entidades/Clientes.php';
  27.  
  28. class OpClientes {
  29.  
  30. function NCodigo() {
  31.  
  32. $con = new Conexion();
  33. $con->Conectar();
  34. //$cli = new Clientes();
  35. //$sql = "call bdejemplos.IdCliente(?)";
  36. $sql = "SELECT nom FROM `clientes where id = ?";
  37. $consulta = $con->prepare($sql);
  38. if ($consulta->execute(array('miguel'))) {
  39. while ($fila = $consulta->fetch()) {
  40. echo "$fila";
  41. }
  42. }
  43. }
  44.  
  45. }
  46.  
  47. $c = new OpClientes();
  48. $c->NCodigo();
  49.  
  50. ?>
  51.  
  52. Fatal error: Call to undefined method Conexion::prepare() in
  53. C:xampphtdocsejemplosModelosOpClientes.php on line 14
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement