busca en google como autentificarse con php y mysql ó como hacer un Login.
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
<?php
/**
* Creador: Coolfrog from Bolivia
* Correo: jm.neutron@gmail.com
* Blog: http://mundocoolf.blogspot.com
* Web Page: ***En progreso***
* Version:1.1
*
* Clase para php5 que permite ejecutar MYSQL, POSTGRESQL E ISIS
* en versiones siquientes se aumentara para oracle y otras que sean necesarias.
* Ultima Acualización 6/8/07
*
* Es cogigo libre y puede ser distribuido a cualquier persona, solo una condicion ,para usar esta clase deben dejar mis datos ;) es lo unico que les agradeceria que hicieran
*/
include("iniDB.php"); //archivo que inicia las variables estaticas, SIRVE PARA TRABAJAR CON UN SOLO MOTOR DE BASE DATOS
class DBALL{
public static $host;
public static $usr;
public static $pass;
public static $dbname;
public static $motor;
private $conex;
private $result;
public static $showErrors;
/*#######DESCOMENTAR EL CONSTRUCTOR SI SE QUIERE TRABAJAR CON DOS O MAS MOTORES DE BASES DE DATOS AL MISMO TIEMPO, Y HACER LA CONEXCION CON EL CONSTRUCTOR PARA CADA MOTOR#######*/
/**
* constructor que inicia las variables
*
* @param str $host
* @param str $usr
* @param str $pass
* @param str $dbname
* @param str $motor
*/
/*function __construct($host,$usr,$pass,$dbname,$motor){
self::$host=$host;
self::$usr=$usr;
self::$pass=$pass;
self::$dbname=$dbname;
self::$motor=$motor;
}*/
/*#####CONSTRUCTOR: DESCOMENTAR HASTA AQUI#####*/
/**
* metodo que conecta a una base de datos dependiendo del parameto $motor
* @return boolean
*/
public function dbConnect(){
self::$motor=strtoupper(self::$motor);
$v=false;
if(self::$motor=="MYSQL"){
$this->conex=mysql_connect(self::$host,self::$usr,self::$pass);
$var=mysql_select_db(self::$dbname,$this->conex);
if($var){
$v=true;
}
} else if(self::$motor=="PSQL"){
$this->conex=@pg_connect("host=".self::$host." dbname=".self::$dbname." user=".self::$usr." password=".self::$pass);
if($this->conex){
$v=true;
}
} else if(self::$motor=="ISIS"){
$this->conex=isis_open(self::$dbname,"-v error -format aligned -encoding ISO8859_1");
if($this->conex){
$v=true;
}
}
//devuelve true si se conecto y false si hay error
return $v;
}
/**
* selecciona registros SELECTS
*
* @param string $consulta
* @return array
*/
public function dbSelect($consulta){
$res=array();
if(self::$motor=="MYSQL"){
$this->result = mysql_query($consulta);
if(self::$showErrors){
if(mysql_errno($this->conex)!=0)
echo "Error ".mysql_errno($this->conex)." : ".mysql_error($this->conex);
}
$fila= mysql_num_rows($this->result);
$i=0;
while ($row = mysql_fetch_object($this->result)){
$res[$i]=$row;
$i++;
}
mysql_free_result($this->result);
}else if(self::$motor=="PSQL"){
$this->result = @pg_query($this->conex,$consulta);
$fila=@pg_numrows($this->result);
for($i=0;$i<$fila;$i++){
$res[$i]=@pg_fetch_object($this->result,$i);
}
@pg_free_result($this->result);
}else if (self::$motor=="ISIS"){
$this->result = isis_query($consulta,$this->conex);
$i=0;
if ($this->result!=null && $this->result!='') {
while($record = isis_fetch_flat_array($this->result)){
$res[$i]=$record;
$i++;
}
}
}
return $res;
}
/**;
* realiza consultas como:UPDATE,INSERT AND DELETE
* retorna true si la consulta se ejecuto correctamente caso contrario false
*
* @param string $consulta
* @return boolean
*/
public function dbABM($consulta){
$r=false;
if(self::$motor=="MYSQL"){
$this->result = mysql_query($consulta);
if(self::$showErrors){
if(mysql_errno($this->conex)!=0)
echo "Error ".mysql_errno($this->conex)." : ".mysql_error($this->conex);
}
//mysql_free_result($this->result);
}else if(self::$motor=="PSQL"){
$this->result = @pg_query($this->conex,$consulta);
pg_free_result($this->result);
}
if ($this->result) {
$r=true;
}
//Devuelve false en caso de error
return $r;
}
/**
* Inicia la transaccion, retorna true si la transaccion se Inicia correctamente caso contrario false
*
* @return Boolean
*/
public function dbBeginTransaction(){
if(self::$motor=="MYSQL"){
$this->result = mysql_query("BEGIN");
}else{
$this->result = pg_query($this->conex,"BEGIN");
}
if ($this->result) {
return true;
//echo "Transaccion Iniciada";
}
else
return false;
}
/**
* Cancela la transaccion, retorna true si la transaccion es cancelada correctamente caso contrario false
*
* @return Boolean
*/
public function dbCancelTransaction(){
if(self::$motor=="MYSQL"){
$this->result = mysql_query("ROLLBACK");
}else{
$this->result = pg_query($this->conex,"ROLLBACK");
}
if ($this->result) {
return true;//$r=true;
//echo "Transaccion Cancelada";
}
else
return false;
}
/**
* Termina la transaccion, retorna true si la transaccion termina correctamente caso contrario false
*
* @return Boolean
*/
public function dbEndTransaction(){
if(self::$motor=="MYSQL"){
$this->result = mysql_query("COMMIT");
}else{
$this->result = pg_query($this->conex,"COMMIT");
}
if ($this->result) {
return true;
//echo "Transaccion Terminada";
} else
return false;
}
public function dbClose(){
if(self::$motor=="MYSQL"){
mysql_close();
}else if(self::$motor=="PSQL"){
pg_close();
}else if (self::$motor=="ISIS"){
@isis_close($this->conex);//$this->dbname,"-v error -format aligned -encoding ISO8859_1"
}
}
// #################### FUNCIONES EXCLUSIVAS PARA ISIS #######################
/*PUEDEN BORRAR O COMENTAR ESTAS FUNCIONES SI NO UTILIZAN ISIS*/
private function num_reg_query(){ //retorna el numer de registros de la consulta
if ($this->result!=null && $this->result!='') {
return isis_num_rows($this->result);
}//else return 0;
}
private function num_reg(){ //retorna el numer de registros de toda la BD
return isis_last_mfn($this->conex);
}
private function get_reg($mfnindex){ //retorna el registro especificado
return isis_fetch_flat_array_from_mfn($mfnindex,$this->conex);
}
// #################### FUNCIONES EXCLUSIVAS PARA ISIS #######################
}
?>
<?php
//parametros de inicio de la base de datos
DBALL::$host="localhost"; //la ruta del servidor donde esta la BD
DBALL::$usr="root"; //el usuario para conectarse
DBALL::$pass="mysql"; //el password para conectarse
DBALL::$dbname="logico"; //nombre de la base de datos
DBALL::$motor="mysql"; //el motor puede ser mysql,postgres o isis
DBALL::$showErrors=true; // indica si se deben mostrar los errores de la BD
?>
$categoria="php"
$categoriaPadre=1
include("DBALL.php"); //incluyen el archivo que contiene la clase
$mydb=new DBALL(); //instancian a la clase
if($mydb->dbConnect()){ //el metodo dbConnect devuelve true si no hay problemas
//una consulta insert
$sql="INSERT INTO CATEGORIA VALUES(default,'$categoria',$categoriaPadre);";
if($mydb->dbABM($sql)) //procesa consultas insert,delete y update
echo "SE INSERTO CORRECTAMENTE");
else echo "NO SE PUEDO INSERTAR";
}
else{
echo "NO SE PUDO CONECTAR";
}
include("DBALL.php"); //incluyen el archivo que contiene la clase
$mydb=new DBALL(); //instancian a la clase
if($mydb->dbConnect()){ //el metodo dbConnect devuelve true si no hay problemas
//una consulta select
$sql="select * from categoria";
$reg=$mydb->dbSelect($sql); //dbSelect devuelve un array de objetos
//para recorrer el array
for($i=0;$i<count($reg);$i++){
echo "<option value=".$reg[$i]->idCat.">".$reg[$i]->nombreCategoria."</option>";
//se accede a los nombres los campos como si fueran propiedades de objetos
}
}
else{
echo "NO SE PUDO CONECTAR";
}
<?php
/**
* Creador: Coolfrog from Bolivia
* Correo: jm.neutron@gmail.com
* Blog: http://mundocoolf.blogspot.com
* Web Page: ***En progreso***
* Version:1.1
*
* Clase para php5 que permite ejecutar MYSQL, POSTGRESQL E ISIS
* en versiones siquientes se aumentara para oracle y otras que sean necesarias.
* Ultima Acualización 6/8/07
*
* Es cogigo libre y puede ser distribuido a cualquier persona, solo una condicion ,para usar esta clase deben dejar mis datos ;) es lo unico que les agradeceria que hicieran
*/
include("iniDB.php"); //archivo que inicia las variables estaticas, SIRVE PARA TRABAJAR CON UN SOLO MOTOR DE BASE DATOS
class DBALL{
public static $host;
public static $usr;
public static $pass;
public static $dbname;
public static $motor;
private $conex;
private $result;
public static $showErrors;
/*#######DESCOMENTAR EL CONSTRUCTOR SI SE QUIERE TRABAJAR CON DOS O MAS MOTORES DE BASES DE DATOS AL MISMO TIEMPO, Y HACER LA CONEXCION CON EL CONSTRUCTOR PARA CADA MOTOR#######*/
/**
* constructor que inicia las variables
*
* @param str $host
* @param str $usr
* @param str $pass
* @param str $dbname
* @param str $motor
*/
/*function __construct($host,$usr,$pass,$dbname,$motor){
self::$host=$host;
self::$usr=$usr;
self::$pass=$pass;
self::$dbname=$dbname;
self::$motor=$motor;
}*/
/*#####CONSTRUCTOR: DESCOMENTAR HASTA AQUI#####*/
/**
* metodo que conecta a una base de datos dependiendo del parameto $motor
* @return boolean
*/
public function dbConnect(){
self::$motor=strtoupper(self::$motor);
$v=false;
if(self::$motor=="MYSQL"){
$this->conex=mysql_connect(self::$host,self::$usr,self::$pass);
$var=mysql_select_db(self::$dbname,$this->conex);
if($var){
$v=true;
}
} else if(self::$motor=="PSQL"){
$this->conex=@pg_connect("host=".self::$host." dbname=".self::$dbname." user=".self::$usr." password=".self::$pass);
if($this->conex){
$v=true;
}
} else if(self::$motor=="ISIS"){
$this->conex=isis_open(self::$dbname,"-v error -format aligned -encoding ISO8859_1");
if($this->conex){
$v=true;
}
}
//devuelve true si se conecto y false si hay error
return $v;
}
/**
* selecciona registros SELECTS
*
* @param string $consulta
* @return array
*/
public function dbSelect($consulta){
$res=array();
if(self::$motor=="MYSQL"){
$this->result = mysql_query($consulta);
if(self::$showErrors){
if(mysql_errno($this->conex)!=0)
echo "Error ".mysql_errno($this->conex)." : ".mysql_error($this->conex);
}
$fila= mysql_num_rows($this->result);
$i=0;
while ($row = mysql_fetch_object($this->result)){
$res[$i]=$row;
$i++;
}
mysql_free_result($this->result);
}else if(self::$motor=="PSQL"){
$this->result = @pg_query($this->conex,$consulta);
$fila=@pg_numrows($this->result);
for($i=0;$i<$fila;$i++){
$res[$i]=@pg_fetch_object($this->result,$i);
}
@pg_free_result($this->result);
}else if (self::$motor=="ISIS"){
$this->result = isis_query($consulta,$this->conex);
$i=0;
if ($this->result!=null && $this->result!='') {
while($record = isis_fetch_flat_array($this->result)){
$res[$i]=$record;
$i++;
}
}
}
return $res;
}
/**;
* realiza consultas como:UPDATE,INSERT AND DELETE
* retorna true si la consulta se ejecuto correctamente caso contrario false
*
* @param string $consulta
* @return boolean
*/
public function dbABM($consulta){
$r=false;
if(self::$motor=="MYSQL"){
$this->result = mysql_query($consulta);
if(self::$showErrors){
if(mysql_errno($this->conex)!=0)
echo "Error ".mysql_errno($this->conex)." : ".mysql_error($this->conex);
}
//mysql_free_result($this->result);
}else if(self::$motor=="PSQL"){
$this->result = @pg_query($this->conex,$consulta);
pg_free_result($this->result);
}
if ($this->result) {
$r=true;
}
//Devuelve false en caso de error
return $r;
}
/**
* Inicia la transaccion, retorna true si la transaccion se Inicia correctamente caso contrario false
*
* @return Boolean
*/
public function dbBeginTransaction(){
if(self::$motor=="MYSQL"){
$this->result = mysql_query("BEGIN");
}else{
$this->result = pg_query($this->conex,"BEGIN");
}
if ($this->result) {
return true;
//echo "Transaccion Iniciada";
}
else
return false;
}
/**
* Cancela la transaccion, retorna true si la transaccion es cancelada correctamente caso contrario false
*
* @return Boolean
*/
public function dbCancelTransaction(){
if(self::$motor=="MYSQL"){
$this->result = mysql_query("ROLLBACK");
}else{
$this->result = pg_query($this->conex,"ROLLBACK");
}
if ($this->result) {
return true;//$r=true;
//echo "Transaccion Cancelada";
}
else
return false;
}
/**
* Termina la transaccion, retorna true si la transaccion termina correctamente caso contrario false
*
* @return Boolean
*/
public function dbEndTransaction(){
if(self::$motor=="MYSQL"){
$this->result = mysql_query("COMMIT");
}else{
$this->result = pg_query($this->conex,"COMMIT");
}
if ($this->result) {
return true;
//echo "Transaccion Terminada";
} else
return false;
}
public function dbClose(){
if(self::$motor=="MYSQL"){
mysql_close();
}else if(self::$motor=="PSQL"){
pg_close();
}else if (self::$motor=="ISIS"){
@isis_close($this->conex);//$this->dbname,"-v error -format aligned -encoding ISO8859_1"
}
}
// #################### FUNCIONES EXCLUSIVAS PARA ISIS #######################
/*PUEDEN BORRAR O COMENTAR ESTAS FUNCIONES SI NO UTILIZAN ISIS*/
private function num_reg_query(){ //retorna el numer de registros de la consulta
if ($this->result!=null && $this->result!='') {
return isis_num_rows($this->result);
}//else return 0;
}
private function num_reg(){ //retorna el numer de registros de toda la BD
return isis_last_mfn($this->conex);
}
private function get_reg($mfnindex){ //retorna el registro especificado
return isis_fetch_flat_array_from_mfn($mfnindex,$this->conex);
}
// #################### FUNCIONES EXCLUSIVAS PARA ISIS #######################
}
?>
<?php
//parametros de inicio de la base de datos
DBALL::$host="localhost"; //la ruta del servidor donde esta la BD
DBALL::$usr="root"; //el usuario para conectarse
DBALL::$pass="mysql"; //el password para conectarse
DBALL::$dbname="logico"; //nombre de la base de datos
DBALL::$motor="mysql"; //el motor puede ser mysql,postgres o isis
DBALL::$showErrors=true; // indica si se deben mostrar los errores de la BD
?>
$categoria="php"
$categoriaPadre=1
include("DBALL.php"); //incluyen el archivo que contiene la clase
$mydb=new DBALL(); //instancian a la clase
if($mydb->dbConnect()){ //el metodo dbConnect devuelve true si no hay problemas
//una consulta insert
$sql="INSERT INTO CATEGORIA VALUES(default,'$categoria',$categoriaPadre);";
if($mydb->dbABM($sql)) //procesa consultas insert,delete y update
echo "SE INSERTO CORRECTAMENTE");
else echo "NO SE PUEDO INSERTAR";
}
else{
echo "NO SE PUDO CONECTAR";
}
$categoria="php"
$categoriaPadre=1
include("DBALL.php"); //incluyen el archivo que contiene la clase
$mydb=new DBALL(); //instancian a la clase
if($mydb->dbConnect()){ //el metodo dbConnect devuelve true si no hay problemas
//una consulta select
$sql="select * from categoria";
$reg=$mydb->dbSelect($sql); //dbSelect devuelve un array de objetos
//para recorrer el array
for($i=0;$i<count($reg);$i++){
echo "<option value=".$reg[$i]->idCat.">".$reg[$i]->nombreCategoria."</option>";
//se accede a los nombres los campos como si fueran propiedades de objetos
}
}
else{
echo "NO SE PUDO CONECTAR";
}
Citarpublic static final long serialVersionUID=0;static es como si fuera una variable global para todas las clases mas o menos como un session en php, final significa que es una constante y el valor de la variable no se podra cambiar. Espero que haya sido de ayuda..
<?php
$sql = "SELECT Usuario FROM Registro";
$result = @mysql_query($sql);
?>
<table width="85%" border="0">
<tr>
<?php
while($row = mysql_fetch_array($result))
{
$usuario = $row['Usuario'];
?>
<td><?php echo $usuario; ?></td>
<?php
}
?>
</tr>
</table>