Category Archives: MySQL

Code Snippets MySQL SQL

Mysql Proper Case

    DROP FUNCTION IF EXISTS proper;
    SET GLOBAL  log_bin_trust_function_creators=TRUE;
    DELIMITER |
    CREATE FUNCTION proper( str VARCHAR(128) )
    RETURNS VARCHAR(128)
    BEGIN
      DECLARE c CHAR(1);
      DECLARE s VARCHAR(128);
      DECLARE i INT DEFAULT 1;
      DECLARE bool INT DEFAULT 1;
      DECLARE punct CHAR(17) DEFAULT ' ()[]{},.-_!@;:?/';
      SET s = LCASE( str );
      WHILE i < LENGTH( str ) DO 
        BEGIN
          SET c = SUBSTRING( s, i, 1 );
          IF LOCATE( c, punct ) > 0 THEN
            SET bool = 1;
          ELSEIF bool=1 THEN 
            BEGIN
              IF c >= 'a' AND c <= 'z' THEN 
                BEGIN
                  SET s = CONCAT(LEFT(s,i-1),UCASE(c),SUBSTRING(s,i+1));
                  SET bool = 0;
                END;
              ELSEIF c >= '0' AND c <= '9' THEN
                SET bool = 0;
              END IF;
            END;
          END IF;
          SET i = i+1;
        END;
      END WHILE;
      RETURN s;
    END;
    |
    DELIMITER ;
MySQL

MySql Group_Concat

The result of GROUP_CONCAT is truncated to the maximum length that is given by the group_concat_max_len system variable, which has a default value of 1024.

This will cause  data-destroying bugs in production. For this reason you should probably not use GROUP_CONCAT . At least you must set the value of group_concat_max_len to an insanely high value on every database server your application runs on.

Like MAX or COUNT, GROUP_CONCAT is a MySQL aggregation function you can use whenever your query contains a GROUP BY. You can use it to retrieve a comma-separated list of all values in a given column within each group.

select  client
,Month
,year
,Sum(Amount) as Amount_Total
,GROUP_CONCAT(Amount) as Amount_Detail
,GROUP_CONCAT(InvoiceNum) as Invoices
from mytable
 group by Client
Backup MySQL Security SQL Tips & tricks Tutorials web services Windows server

Schedule Mysql Backups to Amazon S3 in Windows server 2008 R2

1 – Access Amazon Services, S3
2 – Create a New Bucket if there’s no one.
3 – Create credentials in  IAM Amazon Services
4 – Download the tool s3.exe for windows, from s3.codeplex.com

read more »

Code Snippets Databases MySQL SQL

mysql ‘Proper case’ formating a column?

How to do something like:

Proper(“GALHANO.COM”) = “Galhano.com”

there’s no builtin function to do this but we combine CONCAT and SUBSTRING:

CONCAT(UCASE(SUBSTRING(`fieldName`, 1, 1)),LOWER(SUBSTRING(`fieldName`, 2)))
MySQL

MySQL, CREATE FUNCTION Syntax

The general syntax of Creating a Function is :

 CREATE FUNCTION func_name ([func_parameter[,...]]) RETURNS type routine_body

func_name : Function name
func_parameter : param_name type
type : Any valid MySQL datatype
routine_body : Valid SQL procedure statement

 The RETURN clause is mandatory for FUNCTION . It used to indicate the return type of function.

Now we are describing you a simple example a function. This function take a parameter and it is used to perform an operation by using an SQL function and return the result. In this example there is no need to use delimiter because it contains no internal ; statement delimiters. Example :

CREATE FUNCTION func(str CHAR(20))
RETURNS CHAR(50)
RETURN CONCAT('WELCOME TO, ',str,'!');

Query OK, 0 rows affected (0.00 sec)

 SELECT func('Galhano.com');

 

+------------------------+
| func('Galhano.com')      |
+------------------------+
| WELCOME TO, Galhano.com |
+------------------------+
1 row in set (0.00 sec)

http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

http://www.roseindia.net/mysql/mysql5/stored-procedures-and-functions.shtml

MySQL Open Source SQL Utils

SQLyog – GUI Tool for MySQL

  • The leading Free and Open Source MySQL GUI Tools for the last 5 years
  • Uses Native C MySQL Client – the fastest way to access MySQL

Enterprise Version vs Community version

Homepage: http://www.webyog.com

ASP.Net MySQL

Using MySQL in ASP.Net

Many people have asked me for this tutorial, so here goes.For those of you who don’t know, MySQL is an open-source DataBase server. Being that it’s open-source, it’s also free. That’s about as low-cost as you can get. Of course, you may ask ‘Why use MySQL’? Did you read the previous sentences?? It’s free, as well as being a fairly robust database server!

read more »

MySQL

MaxDB

The software from MySQL AB listed below is licensed under the GNU General Public License (GPL) and is provided “as is” and is without any warranty.

linkÂ

Apache MySQL PHP

Instalando Apache + MySQL + PHP 5 no Windows

1. Download dos itens necessários
Primeiro, faça o download dos programas a serem usados.

Quanto ao Apache, usaremos o Apache 1.3.*, visto que na documentação do PHP existe a seguinte recomendação: “Não use Apache 2.0 e PHP em um sistema de produção, seja no Unix ou no Windows” (http://www.php.net/manual/pt_BR/install.apache2.php).

Apache: http://httpd.apache.org/download.cgi
MySQL: http://dev.mysql.com/downloads/
PHP: http://www.php.net/downloads.php

2. Instalação
– Execute a instalação do Apache e o instale com as configurações padrões. Se quiser, pode escolher outro diretório para a instalação.
РExtraia o MySQL em uma pasta qualquer. Recomendo dentro da pasta onde voc̻ instalou o Apache. Ex: C:\Arquivos de Programas\Apache Group\Apache\mysql
– Extraia o PHP 5 na pasta C:\php5

3. Configuração do PHP
Vá para a pasta c:\php5 e copie o arquivo php5ts.dll para a seguinte pasta, de acordo com o seu Windows:
– c:\windows\system (em Windows 9x/Me)
– c:\windows\system32 (em WindowsXP)
– c:\winnt\system32 (para Windows NT/2000)

Copie também o arquivo c:\php5\libmysql.dll para umas das pastas ditas acima, de acordo com o Windows em uso. Esse arquivo é necessário para o funcionamento do MySQL no PHP.Ainda no c:\php5, renomeie o arquivo “php.ini-dist” para “php.ini” e abra-o. Procure a linha extension_dir = “./” e a altere para extension_dir = “c:/php5/ext/”, é o diretório onde ficam as extensões do php (MySQL, Curl, GD, etc). Agora, localize a linha ;extension=php_mysql.dll e tire o ; do início dela. Se quiser também, já aproveite e faça o mesmo na linha ;extension=php_gd2.dll, caso queira a biblioteca GD para a manipulação de imagens.

Salve as alterações e mova o “php.ini” para a pasta:
– c:\windows (em Windows 9x/Me/XP)
– c:\winnt (para Windows NT/2000)

4. Configuração do Apache
Vá para a pasta onde você instalou o Apache e abra o arquivo conf/httpd.conf em qualquer editor de texto. (Ex: Bloco de Notas).

1º) Localize a linha #LoadModule unique_id_module modules/mod_unique_id.so e logo abaixo dela adicione:
LoadModule php5_module “c:/php5/php5apache.dll”

2º) Localize a linha AddModule mod_setenvif.c e logo abaixo, adicione:
AddModule mod_php5.c

3º) Localize AddType application/x-tar .tgz e logo abaixo, adicione:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

4º) Localize:



DirectoryIndex index.html

E logo ao lado do index.html adicione:
index.php default.php main.php

5. Configuração do MySQL
Não há nada para se configurar no MySQL, você só deve iniciar o mesmo. Vá para a pasta que instalou o MySQL, então abra o bin/mysqld.exe, iniciando o servidor do MySQL.Lembre-se que sempre você terá de iniciar o MySQL. Se não quiser ir na pasta toda vez que iniciar o computador, crie um atalho para o bin/mysqld.exe e coloque no “Iniciar, Programas, Inicializar (ou Iniciar, de acordo com o windows)”.

6. Falta pouco!
Agora, vá em “Iniciar, Programas, Apache HTTP Server, Control Apache Server, Restart”, para reinicializar o Apache com as alterações feitas. Pronto! Agora você pode tem PHP5 + MySQL em seu Windows!.

Para efetuar um teste, crie um arquivo chamado phpinfo.php, com o conteúdo:


();
?>

e o coloque na pasta htdocs dentro da pasta do Apache. Abra seu navegador e digite http://localhost/phpinfo.php. Se a página abrir com as informações do PHP, significa que tudo deu certo.

Observações: Lembrando que nos caminhos que mostrei, o C:\ deve ser substituído pela letra do HD em que está seu Windows e onde foram instalados os programas. Uso o C:\ no artigo, pois é a letra que é normalmente usada.

Caso queira register_globals no PHP, abra o c:\windows\php.ini, localize a linha “register_globals = Off” e arrume para “register_globals = On”. Veja mais aqui: http://www.php.net/manual/pt_BR/security.registerglobals.php

Faça o download do php.ini e do httpd.conf já configurados, você só precisará enviar cada um para as pastas aqui explicadas. Download: http://alfred.auriumsoft.com.br/galeria/arquivos_wamp.zip

Até a próxima!
Alfred Reinold Baudisch
alfred.baudisch@gmail.com
Blog: http://www.auriumsoft.com.br/blog/

Auriumsoft :: Inteligência, Tecnologia e Vídeo
http://www.auriumsoft.com.br

Auriumsoft Hosting
http://www.auriumhost.com.br

por Alfred R. Baudisch

http://phpbrasil.com/articles/article.php/id/847