Guest User

Untitled

a guest
Feb 15th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. ;<?php
  2. ;die(); // /* No modificar sino sabe lo que hace */
  3. ;/*
  4. [database]
  5. driver="mysql"
  6. host="localhost"
  7. port="3306"
  8. schema="bbdd"
  9. username="root"
  10. password="pass"
  11. encode="utf8"
  12. ;*/
  13.  
  14. <?php
  15.  
  16. <?php
  17. $file = 'config.ini.php';
  18. $config = parse_ini_file($file, true);
  19. $host = $config['database']['host'];
  20. $user = $config['database']['username'];
  21. $pass = $config['database']['password'];
  22. $schema = $config['database']['schema'];
  23. $encode = $config['database']['encode'];
  24. class conexion extends mysqli
  25.  
  26. {
  27. public
  28.  
  29. function __construct($host, $user, $pass, $schema)
  30. {
  31. parent::__construct($host, $user, $pass, $schema);
  32. if (mysqli_connect_error())
  33. {
  34. die();
  35. }
  36. }
  37. }
  38.  
  39. $conexion = new conexion($host, $user, $pass, $schema);
  40. mysqli_set_charset( $conexion, $encode);
  41. ?>
  42.  
  43. Documento (HTML-Javascript-CSS, etc) > Nivel 1
  44. Servidor (PHP u otro lenguaje) > Nivel 2
  45. Conexión a la Base de Datos (PDO, MySQLi u otros) > Nivel 3
  46. Configuración de la BD (MySQL u otros) > Nivel 4
  47.  
  48. /* cambiar el conjunto de caracteres a utf8 */
  49.  
  50. if (!$mysqli->set_charset("utf8")) {
  51. printf("Error cargando el conjunto de caracteres utf8: %sn", $mysqli->error);
  52. exit();
  53.  
  54. } else {
  55. printf("Conjunto de caracteres actual: %sn", $mysqli->character_set_name());
  56. }
  57.  
  58. $options = array(
  59. PDO::ATTR_EMULATE_PREPARES => false,
  60. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  61. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"
  62. );
  63. try {
  64. # Intentar la conexión
  65. $pdo = new PDO($dsn, $usr, $pwd, $options);
  66. }
  67. catch (PDOException $e) {
  68. # Escribir posibles excepciones en el error_log
  69. error_log($e->getMessage(),0);
  70. }
  71. ...
Add Comment
Please, Sign In to add comment