Posted By

alberomo on 10/04/11


Tagged

get php classroom LaVioleta dynamicTables


Versions (?)

db_query PHP function for ddbb queries with ADOdb Library


 / Published in: PHP
 

URL: http://phplens.com/adodb/

A PHP function to get a Record Set using ADOdb Library.

It takes the (SQL) query as an argument. For SELECT,UPDATE and DELETE queries.

It also need next variables: $dbhost,$dbuser,$dbpasswd,$dbname (data from de bbdd connexion). Can be declared in the document itself.

It returns the Record Set.

It needs the ADOdb Library for php.

  1. function db_query($sql){
  2. global $db_host,$db_user,$db_passwd,$db_name; //Agafa variables globals (fora de la funcio).
  3. $conn=ADONewConnection('mysql'); //Instancia de ADODB para proveedor MySQL. Es pot elegir motor (segons parametre, podria ser oracle...)
  4. $conn->Connect($db_host,$db_user,$db_passwd,$db_name) ; // Connexion a MySQL. Usa el metodo Connect..
  5. $result=$conn->Execute("SET lc_time_names = 'ca_ES' ;"); //Per adoptar idioma castellano�  (Per errors...)
  6. $result=$conn->Execute("SET NAMES UTF8 ;"); //Pel joc de caracters
  7. $rs=$conn->Execute($sql); // Ejecutar SQL y devuelve un ADORecordSet
  8. $conn->Close();
  9. return $rs; //Funcion devuelve todo el ADORecordSet.
  10. }

Report this snippet  

You need to login to post a comment.