2015年8月24日月曜日

SQLITE データーベース 作成 PHP

SQLITE  データーベース 作成 PHP


<?php
error_reporting(E_ALL);
date_default_timezone_set('Asia/Tokyo');
print_r(SQLite3::version());

if(!file_exists('xtext.db')){
$db = new sqlite3('xtext.db');
$create_title =
"create table title (
url_id text UNIQUE,
title text,
ad_user text default 'admin',
ad_ps text default 'admin_password',
ad_ip text default '0.0.0.0',
ad_agent text default 'Mozilla/5.0',
ad_time text default current_timestamp,
access_time text default current_timestamp,
set_active text default '1',
request_cont integer default 0,
sue_cont integer default 0)";
// set_active 1=非公開、2=公開、3=限定公開、4=削除
// sue_cont >10 非公開
//
$db->exec($create_title);

$create_items =
"create table items (
title_ROWID integer,
item text
)";
$db->exec($create_items);

$create_endusers =
"create table end_user (
url_id UNIQUE,
title_ROWID integer,
item_ROWID integer,
end_name text,
end_ip text default '0.0.0.0',
end_time text default current_timestamp
)";
$db->exec($create_endusers);


$create_agents =
"create table agent (
agent text,
count integer default 0
)";
$db->exec($create_agents);
$db->close();


}else{
echo 'exists';
}
exit;
?>

2015年8月16日日曜日

ランダム文字列 その2

ランダム文字列 その2


function mf_rand()で作成した文字列は重複することがよくあります。
今回の変更は、function mf_rand()は文字列のArrayを作成することに
し、データーベースの比較して、重複する場合、文字列の順番を変える
ことにしました。


<?php
set_time_limit(0);

$db = new sqlite3('xtext.db');
$db->busyTimeout(10000);

for ($i=0; $i<3000; $i++){
//$temp_id = uniqid(mf_rand());
//$temp_id = uniqid();
$temp_id = mf_rand();
do{
shuffle($temp_id);
$temp_id_str = implode($temp_id);
$id_check = $db->querySingle(sprintf("select * from title where url_id='%s'",$temp_id_str),true);
if($id_check){
//print_r ( $id_check);
}
}while($id_check);
$insert = sprintf("insert into title(url_id)VALUES('%s')",$temp_id_str);
$db->exec($insert);
}
$db->close();

function mf_rand(){
$str = array(range('z','a'),range('Z','A'),range('9','0'));
$length = 11;
$str_r =array();
for ($i=0; $i<$length ;$i++){
$temp = $str[array_rand($str)];
$str_r[count($str_r)] = $temp[array_rand($temp)];
}
return($str_r);
}
?>

ランダム文字列

ランダム文字列


結果
18439|kC-EU6_n_Ki||admin|admin_password||1|0
18440|34L95b28gAj||admin|admin_password||1|0
18441|i1U9_95_O2_||admin|admin_password||1|0
18442|NvNl-WklsLm||admin|admin_password||1|0
18443|NwG1_F1-H7n||admin|admin_password||1|0
18444|S--7z5-m7_-||admin|admin_password||1|0
18445|re02t7Z-yXq||admin|admin_password||1|0
18446|sN487lP8_-5||admin|admin_password||1|0
18447|GJo9l_4MN-M||admin|admin_password||1|0
18448|nav-HcE9M3H||admin|admin_password||1|0
18449|w--bl6n1Lh_||admin|admin_password||1|0
18450|-5269e50Hb2||admin|admin_password||1|0
18451|l-71gTkJeSh||admin|admin_password||1|0
18452|G38Pz0Nn21M||admin|admin_password||1|0
18453|-A-A67Hnq1W||admin|admin_password||1|0
18454|1pw890B6X_3||admin|admin_password||1|0
18455|t_Qxo_59nj-||admin|admin_password||1|0
18456|97u7_7B5_qg||admin|admin_password||1|0


Github
https://raw.githubusercontent.com/kankanla/Function/master/rand_uniqid.php



<?php
set_time_limit(0);

$db = new sqlite3('xtext.db');
$db->busyTimeout(10000);

for ($i=0; $i<1000; $i++){
do{
//$temp_id = uniqid(mf_rand());
$temp_id = mf_rand();
//$temp_id = uniqid();
$id_check = $db->querySingle(sprintf("select url_id from title where url_id='%s'",$temp_id));
if($id_check){
echo $id_check;
echo '<br>';
}
}while($id_check);
$insert = sprintf("insert into title(url_id)VALUES('%s')",$temp_id);
$db->exec($insert);
}
$db->close();




function mf_rand(){
$str = array(range('z','a'),range('Z','A'),range('9','0'),range('a','z'),range('A','Z'),range('1','9'),array('_','-'));
$length = 11;
$str_r ='';
for ($i=0; $i<$length ;$i++){
$temp = $str[array_rand($str)];
$str_r = $str_r.$temp[array_rand($temp)];
}
return($str_r);
}

?>



その2

<?php
set_time_limit(0);

$db = new sqlite3('xtext.db');
$db->busyTimeout(10000);

for ($i=0; $i<3000; $i++){
//$temp_id = uniqid(mf_rand());
//$temp_id = uniqid();
$temp_id = mf_rand();
do{
shuffle($temp_id);
$temp_id_str = implode($temp_id);
$id_check = $db->querySingle(sprintf("select * from title where url_id='%s'",$temp_id_str),true);
if($id_check){
//print_r ( $id_check);
}
}while($id_check);
$insert = sprintf("insert into title(url_id)VALUES('%s')",$temp_id_str);
$db->exec($insert);
}
$db->close();

function mf_rand(){
$str = array(range('z','a'),range('Z','A'),range('9','0'));
$length = 11;
$str_r =array();
for ($i=0; $i<$length ;$i++){
$temp = $str[array_rand($str)];
$str_r[count($str_r)] = $temp[array_rand($temp)];
}
return($str_r);
}
?>



2015年8月6日木曜日

Google にアプリケーションIDの取得サイト

Google にアプリケーションIDの取得サイト

https://appengine.google.com/
https://console.developers.google.com/project




2015年6月16日火曜日

javascript 無限ループする方法

javascript 無限ループする方法


その1
var j = 0;
for(;;){
  console.log(j++);
}


その2
var j = 0;
do{
  console.log(j++);
}while(true);




2015年6月10日水曜日

Chrome 開いているタブを選択する方法

Chrome 開いているタブを選択する方法
chrome.tabs.getAllInWindow()


chrome.tabs.getAllInWindow(function(e){
     console.log(e);
});






2015年6月1日月曜日

XMLHttpRequests のLogが表示するための設定

Chrome デフォルトの設定が変わったと思いますが、設定を変更しないと
XMLHttpRequests のLogが表示されない。