Monthly Archives: July 2013

gnu/linux 64 bit with #mysql x86_64 will still break in #2038

gnu/linux 64 bit with mysql x86_64 will still break in 2038

SELECT UNIX_TIMESTAMP('2038-01-01'),UNIX_TIMESTAMP('2039-01-01'),UNIX_TIMESTAMP('2040-01-01');
+------------------------------+------------------------------+------------------------------+
| UNIX_TIMESTAMP('2038-01-01') | UNIX_TIMESTAMP('2039-01-01') | UNIX_TIMESTAMP('2040-01-01') |
+------------------------------+------------------------------+------------------------------+
|                   2145916800 |                            0 |                            0 |
+------------------------------+------------------------------+------------------------------+
1 row in set (0.01 sec)

Advertisements

#mysql howto convert a database and it tables to #utf8

DUMP
mysqldump -h 127.0.0.1 -uMYUSER –skip-quote-names –skip-comments –skip-extended-insert MYDATABASE > db.sql

MODIFY
mysql > alter database MYDATABASE character set = utf8 collate = utf8_general_ci;

PATCH
sed “s/ENGINE=MyISAM/ENGINE=InnoDB/g” < db.sql > db2.sql
sed “s/DEFAULT CHARSET=latin1;/;/g” < db2.sql > db3.sql
sed “s/CHARACTER SET utf8 COLLATE utf8_bin//g” < db3.sql > db4.sql

.MY.CNF
[client]
default-character-set=utf8

RESTORE
mysql -h 127.0.0.1 -uMYUSER < db4.sql

CHECK NEW SETTINGS
mysql > show variables

| character_set_client                    | utf8                       
| character_set_connection                | utf8                       
| character_set_database                  | utf8                       
| character_set_filesystem                | binary                     
| character_set_results                   | utf8                       
| character_set_server                    | latin1                     
| character_set_system                    | utf8                    
   
| collation_connection                    | utf8_general_ci            
| collation_database                      | utf8_general_ci            
| collation_server                        | latin1_swedish_ci

Refs

How to get HTTP headers from CURL response?

Programming in Linux

You can write a simple PHP curl program to download a page. Every HTTP response contains a Header and the contents. In most cases, you will be concerned more about the contents. By default, curl response will give you the contents. But you can also specify that you need the header using the option CURLOPT_HEADER in your program with the curl_setopt function

curl_setopt($curlHandle, CURLOPT_HEADER, true);

Let’s see the complete program which is also give here.

<?php

function downloadURL($URL) {
 if(!function_exists('curl_init')) {
 die ("Curl PHP package not installedn");
 }

 /*Initializing CURL*/
 $curlHandle = curl_init();

 /*The URL to be downloaded is set*/
 curl_setopt($curlHandle, CURLOPT_URL, $URL);
 /*Return the HTTP headers*/
 curl_setopt($curlHandle, CURLOPT_HEADER, true);
 /*Now execute the CURL, download the URL specified*/
 $response = curl_exec($curlHandle);
 return $response;
}

echo downloadURL("http://www.mozilla.org/");
?>

Let’s execute the program

$ php download.php | less

The output of the program will be something like this

HTTP/1.1 200…

View original post 64 more words

#webdev #php type juggling

#webdev #php type juggling and casting and converting to int


<!--?php

PHP
echo 'is_int'.PHP_EOL;
echo is_int(1).PHP_EOL;
echo is_int('1').PHP_EOL;
echo is_int('a').PHP_EOL;
echo is_int('1234').PHP_EOL;
echo 'is_numeric'.PHP_EOL;
echo is_numeric(1).PHP_EOL;
echo is_numeric('1').PHP_EOL;
echo is_numeric('a').PHP_EOL;
echo is_numeric('1234').PHP_EOL;
echo intval(420000000000000000000).PHP_EOL; // 0
echo intval('420000000000000000000').PHP_EOL; // 2147483647

RETURNS

is_int
1
-
is_numeric
1
1
-
1
0
9223372036854775807