db_query PHP function for ddbb queries with ADOdb Library (INSERT queries)


/ Published in: PHP
Save to your folder(s)

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

It takes the (SQL) query as an argument. For INSERT queries. NOTE: A call for a query.

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.


Copy this code and paste it in your HTML
  1. function db_insert($sql){
  2. global $db_host,$db_user,$db_passwd,$db_name;
  3. $conn=ADONewConnection('mysql'); //Instancia de ADODB para proveedor MySQL
  4. $conn->Connect($db_host,$db_user,$db_passwd,$db_name) ; // Connexion a MySQL
  5. $result=$conn->Execute("SET NAMES UTF8 ;");
  6. $rs=$conn->Execute($sql); // Ejecutar SQL y devuelve un ADORecordSet
  7. $ID=$conn->Insert_ID(); //Retorna el ID del registro insertado
  8. $conn->Close();
  9. return $ID;
  10. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.