引用:http://www.phpclasses.org/package/7572-PHP-Setup-MySQL-database-connections.html
<?php
////////////////////////////////////////////
//@Product Name : Connect to MySQL Class //
//@Coding By : hossam Youssef //
//@Copyright © 2010 - 2012 //
////////////////////////////////////////////
// Class
class database {
public $db_host;
public $db_user;
public $db_pass;
public $db_name;
// That to start connection with MySQL
function db_connect(){
// connect with MySQL
$connect = @mysql_connect($this->db_host,$this->db_user,$this->db_pass);
if(!$connect){
@mysql_close($connect);
die ("<h1><font color='#000000'><center>MySQL DataBase Not<font color='#FF0000'style='text-decoration:blink;'> Connected !</font></center></font></h1>");
return false;
}
return true;
}
// Here you have select database with MySQL
function db_select(){
// Select with Database
$select = @mysql_select_db($this->db_name);
if(!$select){
@mysql_close($connect);
die ("<h1><font color='#000000'><center>Not <font color='#FF0000'style='text-decoration:blink;'>Selected</font> DataBase !</center></font></h1>");
return false;
}
return true;
}
// Here you select charset UTF8 with Database
function charset_UTF8(){
// MySQL connection collation UTF8
@mysql_query("SET names 'UTF8'");
@mysql_query("SET charset 'UTF8'");
@mysql_query("SET character_set_client = UTF8");
@mysql_query("SET character_set_connection = UTF8");
@mysql_query("SET character_set_database = UTF8");
@mysql_query("SET character_set_results = UTF8");
@mysql_query("SET character_set_server = UTF8");
}
// MySQL Close connect Function
function close(){
global $connect;
@mysql_close($connect);
}
}
// start show
$db = new database();
/* The hostname of the MySQL server */
$db->db_host = "localhost";
/* The username to login to MySQL */
$db->db_user = "root";
/* The password to login to MySQL */
$db->db_pass = "123";
/* The name of the MySQL database */
$db->db_name = "tesr";
// Call class
$db->db_connect();
$db->db_select();
$db->charset_UTF8();
// Close connect
//$db->close();
?>
同場加映:人生是永遠的測試版:新創企業家改寫生涯的方程式
2012年7月26日 星期四
2012年7月18日 星期三
Convert CSS into programmable CSS with LESS syntax
This class can convert CSS into programmable CSS with LESS (Leaner CSS) syntax.
It can parse a given CSS style sheet and extract certain common property constant values to turn them into variables in the converted output using LESS .
Currently it turns the CSS properties into LESS variables: color, width, height, font-family and font-size.
範例:/test/css2less_sample.php
It can parse a given CSS style sheet and extract certain common property constant values to turn them into variables in the converted output using LESS .
Currently it turns the CSS properties into LESS variables: color, width, height, font-family and font-size.
include_once 'css2less/class.css2less.php';
# sample: creates less source
$css = <<< EOD
#sidebar {
padding: 0;
margin: 0;
font-size: 11px;
width: 217px;
position: absolute;
top: 45px;
left: 0;
background-color: #EFEFEF;
color: #444;
}
#sidebar h3 {
clear: both;
padding: 0;
font-size: 12px;
font-weight: bold;
}
#sidebar input[type='text'],
#sidebar input[type='password'],
#sidebar textarea {
width: 186px;
padding: 6px 5px;
color: #626262;
font-family: "Lucida Grande", "Lucida Sans", "Lucida Sans Unicode", "Luxi Sans", Tahoma, sans-serif;
font-size: 1em;
border: 1px solid #CCC;
box-shadow: inset 0 1px 3px #E4E4E4;
}
EOD;
$cls = new CSS2LESS($css);
$less = $cls->convert();
echo sprintf('<pre>%s</pre>
', $less);
範例:/test/css2less_sample.php
2012年2月19日 星期日
phpExcel
include_once("XXX/phpexcel/PHPExcel/IOFactory.php");
$colum=2;
$num=count($sss);
$objExcel=new PHPExcel();
$objExcel->setActiveSheetIndex(0);
$sheet=$objExcel->getActiveSheet();
for($i=0;$i<$num;$i++){
//if($data[$i]['enable']==0) continue; #因為sql裡面排除不了enable為0的,所以做此處理
$sheet->setCellValueByColumnAndRow(0,$colum,$sss[$i]['Name']);
$sheet->setCellValueByColumnAndRow(1,$colum,$sss[$i]['ID']);
$sheet->setCellValueByColumnAndRow(2,$colum,$sss[$i]['Time']);
$sheet->setCellValueByColumnAndRow(3,$colum,$sss[$i]['eTime']);
$colum++;
}
$path=t_PATH."download/";
$path="../download/";
//2003
$objExcel=PHPExcel_IOFactory::createWriter($objExcel,'Excel5'); //針對2003的版本
$filePath=$path."commodity.xls"; //注意副檔名
// Export to Excel2007 (.xlsx) 匯出成2007
$objExcel=PHPExcel_IOFactory::createWriter($objExcel,'Excel2007'); //針對2003的版本
$filePath=$path."commodity.xlsx"; //注意副檔名
$objExcel->save($filePath);
dl_file($filePath); //此功能應該要和save分開處理,避免產生錯誤
另一個主題:讓phpexcel只讀取column的文字,不會讀取其他的 字體設定,顏色設定。錯誤碼:Cannot use object of type PHPExcel_RichText
原因:去抓 陣列裡的 PHPExcel_RichText ,要抓出我的的文字而不是字體之類的,就產生了錯誤。
$reader->setReadDataOnly(true);
在20120313時需要寫入大量的資料,遇到疑似記憶體不足,但沒顯示任何錯誤,抓bug抓了老半天,始終抓不到。
解法:放在程式最前面
ini_set( "memory_limit", "56M");
設定欄寬範例 : $sheet->getColumnDimension("A")->setWidth(50); //設定欄冠
2012年1月17日 星期二
jQuery Scroll to Top Control v1.1
網址:http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm
引用檔:scrolltopcontrol.js
圖片:up.jpg
修改scrolltopcontrol.js的圖片路徑。
引用檔:scrolltopcontrol.js
圖片:up.jpg
修改scrolltopcontrol.js的圖片路徑。
setting: {startline:100, scrollto: 0, scrollduration:1000, fadeduration:[500, 100]},
controlHTML: '
', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
controlattrs: {offsetx:15, offsety:15}, //offset of control relative to right/ bottom of window corner
anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links
2011年12月22日 星期四
PHPMailer - PHP email class
Software: PHPMailer - PHP email class |
| Version: 2.0.4 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
| Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- |
| Author: Andy Prevost (project admininistrator) |
| Author: Brent R. Matzelle (original founder) |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com): |
| - Web Hosting on highly optimized fast and secure servers |
| - Technology Consulting |
| - Oursourcing (highly qualified programmers and graphic designers)
----------------------------------------------------------------------------|
CASE 2 aXXl
要注意Gmail 的 SMTP主機固定位址是 smtp.gmail.com,必須使用 465 埠以 SSL 的方式來連線
所以apache需要灌ssl才行。
| Version: 2.0.4 |
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
| Info: http://phpmailer.sourceforge.net |
| Support: http://sourceforge.net/projects/phpmailer/ |
| ------------------------------------------------------------------------- |
| Author: Andy Prevost (project admininistrator) |
| Author: Brent R. Matzelle (original founder) |
| Copyright (c) 2004-2007, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
| ------------------------------------------------------------------------- |
| We offer a number of paid services (www.codeworxtech.com): |
| - Web Hosting on highly optimized fast and secure servers |
| - Technology Consulting |
| - Oursourcing (highly qualified programmers and graphic designers)
----------------------------------------------------------------------------|
// 建立 PHPMailer 物件及設定 SMTP 登入資訊
require("../phpMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "remote.smtp.server"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "me@localhost"; // SMTP username
$mail->Password = "123456"; // SMTP password
$mail->From = "myemail@localhost";
$mail->FromName = "My Name";
// 執行 $mail->AddAddress() 加入收件者,可以多個收件者
$mail->AddAddress("to@email.com","Josh Adams");
$mail->AddAddress("to2@email.com"); // optional name
$mail->AddReplyTo("jyu@aemtechnology.com","AEM");
$mail->WordWrap = 50; // set word wrap
// 執行 $mail->AddAttachment() 加入附件,可以多個附件
$mail->AddAttachment("path_to/file"); // attachment
$mail->AddAttachment("path_to_file2", "INF");
// 電郵內容,以下為發送 HTML 格式的郵件
$mail->IsHTML(true); // send as HTML
$mail->Subject = "testing email";
$mail->Body = "This is the HTML body";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent ";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
CASE 2 aXXl
$mail = new PHPMailer(); // defaults to using php "mail()"
$mail->CharSet = "utf-8";
$mail->From = 'admin@XX.XX.X.X';
$mail->FromName = 'AXX';
$subject = " system email test";
$mail->Subject = $subject;
$data_user[0]['id']='xx@xx.xxxx';
$data_user[0]['name']='Bau';
$sql="";
$body = "Dear,
please reply to testing email.";
$data=lazy_get_data($sql);
foreach($data as $value){
$body.=$value['empID'].'gg'.$value['empEmail']."
";
}
//$mail->SingleTo=TRUE; #個人理解,如果cc有多個接收mail只會顯示一個人的
$mail->ClearAddresses(); #由於內文不一樣,$mail->AddAddress 的陣列讓寄信人只寄一個,避免寄給很多人。
// optional, comment out and test
$body = eregi_replace("[\]",'',$body);
$mail->MsgHTML($body);
$mail->Encoding = "base64";
foreach($data_user as $value){
$mail->AddAddress($value['id'], $value['name']);
$mail->IsSMTP();
$mail->SMTPAuth = false;
//$mail->Port = 25;
//需使用SMTP驗證
//ou$mail->SMTPSecure = "ssl";
// 利用SSL連線到伺服器
$mail->Host = "mail.global.frontbridge.com";
//當然啦,信件寄送主機就是GMAIL
//$mail->Port = 465;
//指定SMTP port
//$mail->Username = "";
//MAIL帳號
//$mail->Password = "";
if($debug=='1'){
echo "";
echo $mail->Subject."";
echo $to."[{$to_name}]";
echo $body;
}elseif($debug=='0'){
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
echo $to;
exit;
} else {
//echo "Message sent!";
sleep(3);
}
}
}
要注意Gmail 的 SMTP主機固定位址是 smtp.gmail.com,必須使用 465 埠以 SSL 的方式來連線
所以apache需要灌ssl才行。
訂閱:
文章 (Atom)
