Re: PHP y Access 2000?? ... :-(

From: Date: Wed, 10 Sep 2003 18:40:58 +0000
Subject: Re: PHP y Access 2000?? ... :-(
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-40276@lists.php.net to get a copy of this message
Veamos, un simple ejemplo? prueba.php <? require_once('mylib.inc.php'); require_once('dbclass.inc.php'); $db_type = 'ODBC'; $db = new $db_type('fotos'); $db->quit_on_error(); $query = $db->query('select * from contactos'); $db->quit_on_error(); while ($data = $db->fetch_array($query)) { $handlew = fopen('infos/foto' . $data['CO_NUM_IMAGEN'] . '.txt', 'w'); foreach ($data as $key => $item) { fwrite($handlew, $key . HT . $item . CR . LF); } fclose($handlew); // print_r($data); } ?> mylib.inc.php <? define('HT', "\t"); define('LF', "\n"); define('CR', "\r"); ?> dbclass.inc.php <? class MySQL { var $db; var $database; var $error; var $error_nbr; var $error_str; function MySQL ($db_host = 'localhost', $db_user = '', $db_pass = '') { $this->error = ($this->db = @mysql_connect($db_host, $db_user, $db_pass)); } function set_db ($database) { $this->database = $database; $this->error = @mysql_select_db($this->database, $this->db); return $this->error; } function query ($query_str) { $this->error = @mysql_query($query_str, $this->db); return $this->error; } function db_query ($query_str, $database = '') { $this->error = @mysql_db_query((($database == '') ? ($this->database) : ($database)), $query_str, $this->db); return $this->error; } function fetch_array ($query_result, $result_type = MYSQL_ASSOC) { $this->error = @mysql_fetch_array($query_result, $result_type); return $this->error; } function num_rows ($query_result) { $this->error = mysql_num_rows($query_result); return $this->error; } function get_field ($query_result, $row, $field) { $this->error = mysql_result($query_result, $row, $field); return $this->error; } function is_error () { return !$this->error; } function log_error () { $this->error_nbr = (empty($this->db)) ? (@mysql_errno()) : (@mysql_errno($this->db)); $this->error_str = (empty($this->db)) ? (@mysql_error()) : (@mysql_error($this->db)); } function quit_on_error () { $this->log_error(); if (!$this->error) { echo $this->error_nbr, LF; echo $this->error_str, LF; exit; } } } class ODBC { var $db; var $database; var $error; var $error_nbr; var $error_str; function ODBC ($db_host = 'localhost', $db_user = '', $db_pass = '') { $this->error = ($this->db = @odbc_connect($db_host, $db_user, $db_pass)); } function set_db ($database) { $this->error = true; return $this->error; } function query ($query_str) { $this->error = @odbc_exec($this->db, $query_str); return $this->error; } function db_query ($query_str, $database = '') { $this->error = true; return $this->error; } function fetch_array ($query_result, $result_type = MYSQL_ASSOC) { $this->error = @odbc_fetch_array($query_result); return $this->error; } function is_error () { return !$this->error; } function log_error () { $this->error_nbr = (empty($this->db)) ? (@odbc_error()) : (@odbc_error($this->db)); $this->error_str = (empty($this->db)) ? (@odbc_errormsg()) : (@odbc_errormsg($this->db)); } function quit_on_error () { $this->log_error(); if (!$this->error) { echo $this->error_nbr, LF; echo $this->error_str, LF; exit; } } } ?> En cuanto al código no creo que haya mayor problema (por cierto, esto es un shell-script, un script diseñado para ejecutarse en línea de comandos, en este caso para Windows). En el "Administrador de orígenes de datos ODBC" (asi aparece en W2K) hay que crear un DNS de usuario (o de sistema o archivo... elige la opción que te venga mejor) con los siguiente pasos: 1. Agregar: "Microsoft Access Driver (*.mdb) 2. Nombre del origen de datos: fotos 3. Seleccionar el fichero mdb de la BBDD Access 4. Aceptar y listo ;-) Resulta obvio que el nombre del origen es propio de cada uno ;-) Tambien hay que tener en cuenta que el select que hago, como el procesamiento posterior, es propio de lo que yo queria hacer: extraer todos los registros en ficheros de texto plano separados. Espero que entiendas lo que he querido mostrar, ya que estoy vago y no queria explicar. Saludos

« previous php.general.es (#40276) next »