Sunday, May 27, 2012

PERL / DBI / MYSQL - [Select | Insert]


mysql> create table pessoa (id int(10) primary key auto_increment, nome varchar(45) , telefone int(10));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into pessoa (nome,telefone) values ('Command Line',0000);
Query OK, 1 row affected (0.00 sec)

mysql> select * from pessoa;
+----+--------------+----------+
| id | nome         | telefone |
+----+--------------+----------+
|  1 | Command Line |        0 |
+----+--------------+----------+
1 row in set (0.00 sec)


mysql> desc pessoa;
+----------+-------------+------+-----+---------+----------------+
| Field      | Type         | Null   | Key   | Default | Extra            |
+----------+-------------+------+-----+---------+----------------+
| id          | int(10)        | NO   | PRI | NULL    | auto_increment |
| nome     | varchar(45) | YES  |       | NULL    |                      |
| telefone  | int(10)       | YES  |       | NULL    |                       |
+----------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

file.txt
Kaila   1111
Kalila  2222
Kaori   3333
Karen   4444
Karina  5555
Karine  6666
Karla   7777
Karoline        8888
Kássia 9999
Kate    1010
----------------------------------------------------------------------------


#SELECT 
#!/usr/bin/perl
use strict;
use warnings;
use DBI;

my $database = 'Agenda';
my $user = 'java';
my $password = 'java';

my $dbh = DBI->connect("DBI:mysql:$database", "$user", "$password" ) || die "Could not connect to database: $DBI::errstr";

my $sth = $dbh->prepare('SELECT *  FROM pessoa');

$sth->execute();

while(my @result = $sth->fetchrow_array() ){
        print join ("\t",@result),"\n";
}

$dbh->disconnect();

---------------------------------------------------------------------------


als:/blog$ perl select_mysql_PERL.pl 
1 Command Line 0

---------------------------------------------------------------------------
#INSERT
#!/usr/bin/perl
use strict;
use warnings;
use DBI;

my $database = 'Agenda';
my $user = 'java';
my $password = 'java';

my $dbh = DBI->connect("DBI:mysql:$database", "$user", "$password" ) || die "Could not connect to database: $DBI::errstr";

my $sth = $dbh->prepare( q{ INSERT INTO pessoa (nome,telefone) VALUES (?, ?)}) or die $dbh->errstr;

open (File,"file.txt") or die $!;
while (<File>) {
        chomp;
        my ($nome,$telefone) = split (/\t/,$_);
        $sth->execute($nome,$telefone) or die $dbh->errstr;
}
close();
$dbh->disconnect();

---------------------------------------------------------------------------

als:/blog$ perl insert_mysql_PERL.pl 
als:/blog$ perl select_mysql_PERL.pl 
1 Command Line 0
2 Kaila 1111
3 Kalila 2222
4 Kaori 3333
5 Karen 4444
6 Karina 5555
7 Karine 6666
8 Karla 7777
9 Karoline 8888
10 Kássia 9999
11 Kate 1010

mysql> select * from pessoa;
+----+--------------+----------+
| id | nome         | telefone |
+----+--------------+----------+
|  1 | Command Line |        0 |
|  2 | Kaila        |     1111 |
|  3 | Kalila       |     2222 |
|  4 | Kaori        |     3333 |
|  5 | Karen        |     4444 |
|  6 | Karina       |     5555 |
|  7 | Karine       |     6666 |
|  8 | Karla        |     7777 |
|  9 | Karoline     |     8888 |
| 10 | Kássia      |     9999 |
| 11 | Kate         |     1010 |
+----+--------------+----------+
11 rows in set (0.00 sec)

It shares.

Monday, May 14, 2012

Sunday, May 13, 2012

HTML BASIC TAG



TAG
<html></html>
Inicia/termina um documento em HTML.
<head></head>
Define a àrea de cabeçalho, com elementos não visualisáveis na página.
<body></body>
Define a área visível do documento.
CABEÇALHO
<title></title>
Coloca o nome da página na barra de título da janela.
ATRIBUTOS DO CORPO
<body bgcolor=?>
Cor de fundo.
<body text=?>
Cor de texto.
<body link=?>
Cor das links.
<body vlink=?>
Cor das links previamente visitadas.
<body alink=?>
Cor da link activa.
TEXTO
<b></b>
Texto carregado.
<i></i>
Texto em itálico.
<tt></tt>
Texto estilo máquina de escrever, monoespaçamento.
<font size=?></font>
Tamanho das letras.
<font color=?></font>
Cor das letras.
<font face=?></font>
Define a fonte utilizada.
LINKS
<a href="URL"></a>
Cria uma hiperligação.
<a href="mailto:EMAIL"></a>
Cria uma link para o envio de correio.
<a name="NOME"></a>
Cria um 'alvo' dentro de uma página.
<a href="#NAME"></a>
Faz a ligação a um 'alvo' presente dentro da mesma página.
FORMATAÇÃO
<p></p>
Define a área de um parágrafo.
<p align=?>
Alinhamento de um parágrafo.
<br>
Insere uma quebra de linha.
<div align=?>
'Tag' genérico utilizado para formatar blocos de texto.
GRAFISMO
<img src="FICHEIRO">
Insere uma imagem.
<img src="FICHEIRO" align=?>
Alinha uma imagem em relação ao resto do texto.
<img src="FICHEIRO" border=?>
Define a borda da imagem.
<hr>
Insere uma linha horizontal.
TABELAS
<table></table>
Cria uma tabela.
<tr></tr>
Linha de uma tabela
<td></td>
Célula individual numa linha.
ATRIBUTOS DAS TABELAS
<table border=#>
Borda à volta de cada célula.
<table cellspacing=#>
Espaço entre as células.
<table cellpadding=#>
Margem interior das células.
<table width=# or %>
Largura da tabela - em pixels ou percentagem.
<tr align=?> or <td align=?>
Alinhamento horizontal do conteúdo das células.quot;left", "center" ou "right")
<tr valign=?> or <td valign=?>
Alinhamento vertical do conteúdo das células.("top", "middle" ou "bottom")
<td colspan=#>
Numero de colunas 'percorridas' por uma célula.
<td rowspan=#>
Numero de linhas 'percorridas' por uma célula.
FRAMES
<frameset></frameset>
Define o conjunto de frames. Surge antes de <body> num documento com frames.
<frameset rows="valor,valor">
Define as linhas num conjunto de frames. Valor pode ser em pixels, percentagem ou * (o resto / proporção).
<frameset cols="valor,valor">
Define as colunas num conjunto de frames. Valor pode ser em pixels, percentagem ou * (o resto / proporção).
<frame>
Define uma unica frame. Surge dentro de <frameset>.
<noframes></noframes>
Área onde é inserido o conteúdo visivel em browsers que não suportam o uso de frames.
ATRIBUTOS DE UMA FRAME
<frame src="URL">
Especifica o documento HTML a ser exibido na frame.
<frame name="nome">
Dá um nome à frame de modo a poder ser 'linkada' a partir de outras frames.
<frame scrolling=VALOR>
Define se a frame tem barra de scroll. VALOR pode ser "yes", "no" ou "auto".
<frame noresize>
Impede o visitante de redimensionar a frame.



font : http://www.truquesedicas.com/tutoriais/html/00007a.htm

Thursday, May 10, 2012

Mysql : ERROR 1045 (28000) | Solution

root@lucid32:/home/vagrant# mysql -u root -w 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

root@lucid32:/home/vagrant# /etc/init.d/mysql stop

root@lucid32:/home/vagrant# mysqld_safe --skip-grant-tables &
[1] 1152
root@lucid32:/home/vagrant# 120509 19:36:25 mysqld_safe Logging to syslog.
120509 19:36:26 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

root@lucid32:/home/vagrant# ^C
root@lucid32:/home/vagrant# /etc/init.d/mysql start 
Rather than invoking init scripts through /etc/init.d, use the service(8)
utility, e.g. service mysql start

Since the script you are attempting to invoke has been converted to an
Upstart job, you may also use the start(8) utility, e.g. start mysql
mysql start/running, process 1297

root@lucid32:/home/vagrant# mysql --user root -w 

root@lucid32:/home/vagrant# sudo mysqladmin -u roor password 12345

Sunday, May 6, 2012

MySQL | Create New MySQL User


$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> CREATE USER 'java'@'localhost' IDENTIFIED BY 'java';
Query OK, 0 rows affected (0.09 sec)

mysql> GRANT select , insert , update , delete , create , drop , references , execute on *.* to 'java'@'localhost';
Query OK, 0 rows affected (0.00 sec)


mysql>  GRANT select , insert , update , delete , create , drop , references , execute on *.* to 'java'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

$ mysql -u java -p
Enter password: java

Mysql | SQL → basic

SQL. key word

SELECT        

→ retrieves data from one or more tables


Sintaxe SELECT * FROM nameTable
Ex: SELECT name , old  FROM person


FROM 
→ tables involved in the query. Required in each SELECT
Sintaxe →  SELECT * FROM nameTable
Ex: SELECT name , old  FROM person


WHERE        
→ Selection criterion that determines the rows to be retrieved.
Sintaxe → SELECT coll1,coll2 FROM person WHERE  criterion
Ex: SELECT name, old FROM person WHERE old > '18'


GROUP BY   
→ Criteria for grouping rows


ORDER BY   
→ Criteria for odenar lines
Sintaxe → SELECT coll1,coll2 FROM person ORDER BY   coll ASC|DESC
Ex: SELECT name,old FROM person ORDER BY  old 
Ex: SELECT name,old FROM person ORDER BY  old  ASC 
Ex: SELECT name,old FROM person ORDER BY  old  DESC


INNER JOIN 
→ Merge multiple rows of tables
Sintaxe → SELECT coll1,coll2 FROM table1 INNER JOIN table2 ON table1.coll1 = table2.coll2 
Ex: SELECT name,old FROM person INNER JOIN person2 ON person.name = person2.name
Ex: SELECT name,old FROM person INNER JOIN person2 ON person.name = person2.name ORDER BY person.old


INSERT        
→ Insert row in a table specifies
Sintaxe → INSERT INTO nameTable (coll1,coll2,coll3,...) VALUES(val1,val2,val3,...)


UPDATE      
 → update row in a table specifies
Sintaxe UPDATE nameTable SET nameColl1 = value,  nameColl2 = value WHERE criterion
Ex: UPDATE person SET name = ComandLine WHERE name = Blog


DELETE       
 →Delete row in a table specifies
Sintaxe →  DELETE FROM nameTable WHERE criterion
Ex: DELETE FROM person WHERE name = 'Silva'  END old = '22'  


Share this page. 

Installing MySQL + Apache + PHP + phpMyAdmin | Linux - Like

$sudo su 

#apt-get update

#apt-get -f install mysql-server
Do you want to continue [Y/n]? Y

#apt-get -f install apache2
Do you want to continue [Y/n]? Y

#apt-get -f install php5
Do you want to continue [Y/n]? Y

#apt-get -f install php5-mysql
Do you want to continue [Y/n]? Y

#apt-get -f install phpmyadmin
Do you want to continue [Y/n]? Y

#cp -R usr/share/phpmyadmin/ /var/www/
#chown www-data.www-data /var/www/phpmyadmin

access : http://127.0.0.1
access : http://127.0.0.1/phpmyadmin

Attention. 
Read all instructions during installation.
NOTEsame password for all software.

Share this page.

Friday, May 4, 2012