miércoles, 18 de diciembre de 2013

COMANDOS MYSQL


INSERT
inserta nuevos registros en una tabla existente NSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] VALUES ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr, ... ]


UPDATE

El comando UPDATE actualiza columnas en registros de tabla existentes con nuevos valores. La cláusula SET indica qué columna modificar y los valores que puede recibir.
UPDATE [LOW_PRIORITY] [IGNORE] table_references SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]


DELETE
DELETE borra los registros de una tabla que satisfacen la condición dada por el predicado, y retorna el número de registros borrados.
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [WHERE where_definition] [ORDER BY ...] [LIMIT row_count]


SELECT

se usa para recibir registros seleccionados desde una o más tablas. MySQL 5.0 incluye soporte para comandos UNION y subconsultas.
SELECT college, region, seed FROM tournament ORDER BY region, seed;
 
 

lunes, 16 de diciembre de 2013

MYSQL


mysql_select_db

Seleccionar una base de datos MySQL

$enlace = mysql_connect('localhost', 'usuario', 'contraseña');



mysql_query

Enviar una consulta MySQL

$resultado = mysql_query('SELECT * WHERE 1=1');



mysql_close

Cierra una conexión de MySQL

mysql_close($enlace);



mysql_connect
Abre una conexión al servidor MySQL

resource mysql_connect ([ string $server = ini_get("mysql.default_host") [,string $username = ini_get("mysql.default_user") [, string $password = ini_get("mysql.default_password") [, bool $new_link = false [, int$client_flags = 0 ]]]]] )



die
Devuelve el texto del mensaje de error de la operación MySQL anterior

$enlace = mysql_connect("localhost", "usuario", "contraseña");

mysql_select_db("bd_inexistente", $enlace);
echo mysql_errno($enlace) . ": " . mysql_error($enlace). "no conexion";

miércoles, 11 de diciembre de 2013

PRUEBA

MENU PRINCIPAL
<!DOCTYPE html>
<?php
    session_start(); 
?>

<html >
    <head>
            <title>Crear una sesión</title>
    </head>
     
    <body>
<CENTER>
            <h1>USARIO</h1>
            <form action="session.php" method="POST">
                    <p>
                            <label>NOMBRE</label> <br />
                            <input type="text" name="username" />
                    </p>
<p>
                            <label>CLAVE</label> <br />
                            <input type="PASSWORD" name="clave" />
                    </p>
<p>
                            <label>COREEO</label> <br />
                            <input type="text" name="correo" />
                    </p>
     
                    <p>
                            <input type="submit" value="INICIAR" />
                    </p>
            </form>
    </body>

</html>

SESSION

<?php
    session_start();
function correo($valor)
{
if (preg_match('{^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$}',$valor))
return true;
else
return false;
}
class USUARIOS
{
function INICIAR($A)
{
ECHO "A INICIADO SESSION ".$A;

}
function REGISTRAR()
{
$_SESSION['username'] = $_POST['username'];
$_SESSION['clave'] = $_POST['clave'];
}

function CERRAR()
{
echo "<a href='Index2.PHP'>CERRAR CESSION</a>";
}
}

if($_POST["username"]==$_SESSION['username'] && $_POST["clave"]=="123")
{
$correo=$_POST['correo'];
if (correo($correo))
{
$a=$_POST['username'];
$usu= new USUARIOS();
$usua=$usu->INICIAR($a);
echo "<br>";
$usua=$usu->REGISTRAR();
echo "<br>";
$usua=$usu->CERRAR();

}
else
echo "<a href='INTENTOS.PHP'>INTENTOS</a>";

}
else
echo "<a href='INTENTOS.PHP'>INTENTOS</a>";
?>



INGRESOS FALLIDOS

<?PHP
session_start();
echo "INTENTOS FALLIDOS: ".$_SESSION['cont']=$_SESSION['cont']+1;
ECHO "<BR>";
ECHO date('c');
ECHO "<BR>";
echo "<a href='Index2.PHP'>INICIO</a>";
?>
     



martes, 10 de diciembre de 2013

OPERACIONES

CODIGO PHP
  ---->MENU

<html>
<?php
echo "<FORM ACTION='menuoperaciones.php' method='POST'>";
ECHO "<H1>MENU</H1>";
echo "<H3>1)<input type='submit' value='suma' name='suma'></H3>";
echo "<H3>2)<input type='submit' value='resta' name='resta'></H3>";
echo "<h3>3)<input type='submit' value='multiplicacion' name='multi'></H3>";
echo "<H3>4)<input type='submit' value='divicion' name='divi'></H3>";
echo "</form>";
if( isset($_POST['suma']))

echo "<FORM ACTION='RESULTADOclass.php' method='POST'>";
echo "<H3>NUMERO 1<input type='TEXT'  name='uno'></H3>";
echo "<H3>NUMERO 2<input type='TEXT'  name='dos'></H3>";
echo "<H3><input type='submit'  value='sumar' name='sum'></H3>";
echo "</form>";
}
if( isset($_POST['resta']))

echo "<FORM ACTION='RESULTADOclass.php' method='POST'>";
echo "<H3>NUMERO 1<input type='TEXT'  name='uno'></H3>";
echo "<H3>NUMERO 2<input type='TEXT'  name='dos'></H3>";
echo "<H3><input type='submit'  value='restar' name='res'></H3>";
}
if( isset($_POST['multi']))

echo "<FORM ACTION='RESULTADOclass.php' method='POST'>";
echo "<H3>NUMERO 1<input type='TEXT'  name='uno'></H3>";
echo "<H3>NUMERO 2<input type='TEXT'  name='dos'></H3>";
echo "<H3><input type='submit'  value='multiplicar' name='mul'></H3>";
}
if( isset($_POST['divi']))

echo "<FORM ACTION='RESULTADOclass.php' method='POST'>";
echo "<H3>NUMERO 1<input type='TEXT'  name='uno'></H3>";
echo "<H3>NUMERO 2<input type='TEXT'  name='dos'></H3>";
echo "<H3><input type='submit'  value='dividir' name='div'></H3>";
}
?>

</html>


-->RESULTADOS

<?PHP
CLASS OPERACIONES{
function SUMAR($UNO,$DOS){
ECHO "RESULTADO: ".$R=$UNO+$DOS;
}
function RESTA($UNO,$DOS){
ECHO "RESULTADO: ".$R=$UNO-$DOS;
}
function MULTIPLICAR($UNO,$DOS){
ECHO "RESULTADO: ".$R=$UNO*$DOS;
}
function DIVIDIR($UNO,$DOS){
ECHO "RESULTADO: ".$R=$UNO/$DOS;
}
}
if( isset($_POST['sum']))
{
$uno=$_POST['uno'];
$dos=$_POST['dos']; 
$sum= new OPERACIONES();
$suma=$sum->SUMAR($uno,$dos);
}
if( isset($_POST['res']))
{
$uno=$_POST['uno'];
$dos=$_POST['dos']; 
$res= new OPERACIONES();
$resta=$res->RESTA($uno,$dos);

if( isset($_POST['mul']))
{
$uno=$_POST['uno'];
$dos=$_POST['dos']; 
$mul= new OPERACIONES();
$mult=$mul->MULTIPLICAR($uno,$dos);

if( isset($_POST['div']))
{
$uno=$_POST['uno'];
$dos=$_POST['dos']; 
$div= new OPERACIONES();
$divi=$div->DIVIDIR($uno,$dos);
}  



?>


jueves, 5 de diciembre de 2013

CLASS TRANSPORTE

<?php
class Transporte {
var $Tipo;
var $modelo;
var $marca;
function acelerar($Modelo,$Marca){
$this->modelo=$Modelo;
$this->marca=$Marca;
echo "<br>" ;
echo "A empezado a moverse: ".$this->modelo;
echo "<br>";
echo " Su modelo es: ".$this->marca;
echo "<br>";
}
function frenar($modelo,$marca){
$this->Modelo=$modelo;
$this->Marca=$marca;
echo "<br>" ;
echo "A frenado: ".$this->Modelo;
echo "<br>";
echo " Su modelo es: ".$this->Marca;
echo "<br>";
}
function Transportes($tip){
$this->Tipo=$tip;
echo "tipo de transporte: ".$this->Tipo;
echo "<br>";
}
}
$transporte= new Transporte();
$auto=$transporte->Transportes("auto");
$auto=$transporte->frenar("2013","mazda");
$auto=$transporte->acelerar("2013","mazda");


CLASS OTROTRANSPORTE extends Transporte
{
FUNCTION OTROMEDIO()
{ECHO "<BR>OTRO TIPO DE TRANSPORTE: CABALLO";
}
}

$otrotrans=new OTROTRANSPORTE();
$caballo=$otrotrans->otromedio();
$caballo=$otrotrans->acelerar("2010","caballo loco")
?>

miércoles, 4 de diciembre de 2013

DEBER

QUE SON CLASES EN PHP?
Una clase es una colección de variables y funciones que trabajan con estas variables. las variables se definen utilizando var y las funciones utilizando function.

EJEMPLO:




<?php
class Cart {
var $items; // Objetos en nuestro carrito de compras

// Agregar $num artículos de $artnr al carrito

function add_item($artnr, $num) {
$this->items[$artnr] += $num;
}

// Sacar $num artículos de $artnr fuera del carrito

function remove_item($artnr, $num) {
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} elseif ($this->items[$artnr] == $num) {
unset($this->items[$artnr]);
return true;
} else {
return false;
}
}
}
?>

OBJETOS
Para crear un nuevo object, utilice la declaración new para instanciar una clase:
?php
class foo
{
function do_foo()
{
echo "Doing foo.";
}
}

$bar = new foo;
$bar->do_foo();
?>





CLASES

CODIGO PHP

<?php
class animales {
var $habi;
var $ali;
var $tipo;
var $anim;
function Tipo($tipo)
{$this->Tipo=$tipo;
echo "TIPO:   ".$this->Tipo;
}
function habitad($habi)
{$this->Habi=$habi;
echo "HABITAD: ".$this->Habi;
}
function alimento($ali)
{$this->Ali=$ali;
echo "ALIMENTO: ".$this->Ali;
}
function gato($anim){
$this->ani=$anim;
echo "NOMBRE: ".$this->ani;
}
function nace()
{echo "Nace";
}
function crecer(){
echo " Crece ";
}
function reproducirce(){
echo "Luego se reproduce";
}
function Morir(){
echo " y finalmente muere";
}
}
$animales=new animales();
$gato=$animales->Tipo("mamifero");
echo "<br>";
$gato=$animales->habitad("domestico");
echo "<br>";
$GATO=$animales->alimento("ratones");
echo "<br>";
$gato=$animales->gato(" gato");
echo "<br>";
$gato=$animales->nace();
echo "<br>";
$gato=$animales->crecer();
echo "<br>";
$gato=$animales->reproducirce();
echo "<br>";
$gato=$animales->Morir();
?>