PHP 的 邏輯運算元:AND/&&、OR/|| 這是常使用的運算元
而,AND 與 && 都是 AND 運算,有差別嗎?
有,其運算的優先次序不同。
&& 的運算次序高於 = , = 高於 AND
OR 一樣。
為了便於可讀性,我們建議一律使用可讀性高的表示法
如果有多個運算元在一起的運算式,就使用()來明確的表示優先次序,不要使用 && 這類不容易閱讀的運算元。
本網誌記錄網站設計的一些內容筆記。 網站設計需要整合很多工具與概念。 我畢業自淡江電子計算機科學學系,算是科班出身。但我們那個年代(50年代,唉!LKK了!),網路還只是剛開始,相關的技術都是出社會以後陸續接觸學習。 網站的建立與設計,牽涉的範圍真的很廣泛。 網站的目地是甚麼?銷售網頁、電子購物、廣告、社群經營、互動、教學、客戶服務、網站應用程式、...... 需要整合的人才,程式設計師、資料庫管理師、網頁美編、文字編輯、多媒體製作等等。 這裡將記錄一個LKK對網站系統重新學習與複習,還有教學使用的一些資料。
PHP 的 邏輯運算元:AND/&&、OR/|| 這是常使用的運算元
而,AND 與 && 都是 AND 運算,有差別嗎?
有,其運算的優先次序不同。
&& 的運算次序高於 = , = 高於 AND
OR 一樣。
為了便於可讀性,我們建議一律使用可讀性高的表示法
如果有多個運算元在一起的運算式,就使用()來明確的表示優先次序,不要使用 && 這類不容易閱讀的運算元。
CRON設定是最少一分鐘執行一次。
如果要小於60秒執行一次,就需要額外技巧:配合 sleep 30; 指令完成。
秒數必須是 60秒可以整除的,這樣才不會亂!例如:30秒、20秒、15秒、10秒等。
只要在 CRON 中這樣下:
* * * * <指令1>
* * * * sleep 30; <指令1>
這樣就可以一分鐘內,30秒自動執行一次。
如果是20秒,如下:
* * * * <指令1>
* * * * sleep 20; <指令1>
* * * * sleep 20; <指令1>
這樣就是一分鐘內,執行三次,每20秒一次。
Constant 重複定義了!
找到這個指令:
define('DS', DIRECTORY_SEPARATOR);
修改成這樣就可以了:
if(!defined('DS')){ define('DS',DIRECTORY_SEPARATOR); }
GhostScript:
https://www.ghostscript.com/index.html
下載:
https://www.ghostscript.com/releases/gsdnld.html
安裝:
在SSH終端上:
cd /usr/src
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs9550/ghostscript-9.55.0.tar.gz
tar -xzvf ghostscript-9.55.0.tar.gz
cd ghostscript-9.55.0
./configure
make
make install
在 使用 Imagick,使用 PDF 轉換 JPG,一直發生 Internal Error 500
經查了很久,才知道,Server必須安裝 PHP Imagick 以外,還有 GhostScript,這是一個 PDF 要用的免費程式。
我的主機上沒有,所以必須安裝起來。
在 PDF Report 裡面的 PDF Layout Code下面增加產生 PDF,轉 JPG 的程式
因為,我們不知道 SC產生的 PDF 檔案名稱,只好自己用自訂的PDF檔名來產生
然後,再由自己產生的 PDF 產生 JPG
$t_pdf_file = $_SERVER['DOCUMENT_ROOT']."/_lib/tmp/id_".{pay_form_id}."_pay_form.pdf";
$t_jpg_file = $_SERVER['DOCUMENT_ROOT']."/_lib/tmp/id_".{pay_form_id}."_pay_form.jpg";
$pdf->output($t_pdf_file,"F");
$im = new Imagick();
$im->setResolution(150, 150);
$im->readImage( $t_pdf_file );
$im->writeImages( $t_jpg_file, false );
** 還有 /domains/<websitename>.com/public_html/_lib/prod/third/wkhtmltopdf/linux-amd64/wkhtmltopdf-amd64 權限要設成 "777"
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Escape special characters, if any
$firstname = $mysqli -> real_escape_string($_POST['firstname']);
$lastname = $mysqli -> real_escape_string($_POST['lastname']);
$age = $mysqli -> real_escape_string($_POST['age']);
$sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES ('$firstname', '$lastname', '$age')";
if (!$mysqli -> query($sql)) {
printf("%d Row inserted.\n", $mysqli->affected_rows);
}
$mysqli -> close();
?>
像下面這個例子: $lastname 裡面的值有單引號。這樣進入 SQL 就會發生錯誤,應該要避開。
就使用這個函數:mysqli_real_escape_string(),就可以把單引號等避開了!
<?php
$lastname = "D'Ore";
$sql="INSERT INTO Persons (LastName) VALUES ('$lastname')";
// This query will fail, cause we didn't escape $lastname
if (!$mysqli -> query($sql)) {
printf("%d Row inserted.\n", $mysqli->affected_rows);
}
?>
https://www.w3schools.com/php/func_mysqli_real_escape_string.asp
https://www.php.net/manual/en/mysqli.real-escape-string.php
IF NEW.execute_it = "1" THEN
-- Execute some code...
SET NEW.execute_it = "0";
ELSE
-- Execute the other code......
END IF;
SET NEW.execute_it = "0";
Name | Default | Description | Changeable |
---|---|---|---|
allow_url_fopen | "1" | Allows fopen()-type functions to work with URLs (available since PHP 4.0.4) | PHP_INI_SYSTEM |
user_agent | NULL | Defines the user agent for PHP to send (available since PHP 4.3) | PHP_INI_ALL |
default_socket_timeout | "60" | Sets the default timeout, in seconds, for socket based streams (available since PHP 4.3) | PHP_INI_ALL |
from | "" | Defines the anonymous FTP password (your email address) | PHP_INI_ALL |
auto_detect_line_endings | "0" | When set to "1", PHP will examine the data read by fgets() and file() to see if it is using Unix, MS-Dos or Mac line-ending characters (available since PHP 4.3) | PHP_INI_ALL |
函數 Function | 敘述 |
---|---|
basename() | 傳回一個路徑的 檔案名稱 部分 |
chgrp() | 改變檔案所屬的 群組 group |
chmod() | 改變檔案 模式 mode |
chown() | 改變檔案擁有者 file owner |
clearstatcache() | 清除檔案狀態快取 file status cache |
copy() | 複製一個檔案 |
delete() | 請閱 unlink() 或 unset() |
dirname() | 傳回一個路徑的目錄部分 Returns the directory name component of a path |
disk_free_space() | 傳回一個目錄的自由可用空間 Returns the free space of a directory |
disk_total_space() | 傳回一目錄的總共空間 Returns the total size of a directory |
diskfreespace() | 跟 disk_free_space() 一樣的。別名而已。 |
fclose() | 關閉一個開啟的檔案 |
feof() | 測試一個開啟檔案的 end-of-file |
fflush() | Flushes buffered output to an open file |
fgetc() | 傳回開啟檔案的一個字元 Returns a character from an open file |
fgetcsv() | 傳回開啟檔案的一行,CSV格式 Parses a line from an open file, checking for CSV fields |
fgets() | 傳回開啟檔案的一行 Returns a line from an open file |
fgetss() | 傳回開啟檔案的一行,移除HTML, PHP的標籤 Returns a line, with HTML and PHP tags removed, from an open file |
file() | 讀取檔案到一個陣列中 Reads a file into an array |
file_exists() | 檢查檔案或目錄是否存在 Checks whether or not a file or directory exists |
file_get_contents() | 讀取檔案進入一個字串變數 Reads a file into a string |
file_put_contents() | 將一個字串變數寫入檔案 Writes a string to a file |
fileatime() | 傳回檔案最後一次存取的時間 Returns the last access time of a file |
filectime() | 傳回檔案最後一次改變的時間 Returns the last change time of a file |
filegroup() | 傳回檔案的 群組 ID Returns the group ID of a file |
fileinode() | 傳回檔案的 inode 號碼 Returns the inode number of a file |
filemtime() | 傳回檔案最後修改的時間 Returns the last modification time of a file |
fileowner() | 傳回檔案擁有者的 user ID Returns the user ID (owner) of a file |
fileperms() | 傳回檔案的權限資料 Returns the permissions of a file |
filesize() | 傳回檔案大小 Returns the file size |
filetype() | 傳回檔案格式 Returns the file type |
flock() | 鎖定或釋放檔案 Locks or releases a file |
fnmatch() | 比對 檔案名稱或字串 Matches a filename or string against a specified pattern |
fopen() | 開啟檔案 Opens a file or URL |
fpassthru() | 讀取一個開啟的檔案,直到EOF,然後將結果寫到output buffer Reads from an open file, until EOF, and writes the result to the output buffer |
fputcsv() | 將一行格式成CSV,然後寫到開啟的檔案 Formats a line as CSV and writes it to an open file |
fputs() | 跟 fwrite()一樣 Alias of fwrite() |
fread() | 從開啟的檔案讀取 Reads from an open file |
fscanf() | Parses input from an open file according to a specified format |
fseek() | Seeks in an open file |
fstat() | Returns information about an open file |
ftell() | Returns the current position in an open file |
ftruncate() | Truncates an open file to a specified length |
fwrite() | Writes to an open file |
glob() | Returns an array of filenames / directories matching a specified pattern |
is_dir() | Checks whether a file is a directory |
is_executable() | Checks whether a file is executable |
is_file() | Checks whether a file is a regular file |
is_link() | Checks whether a file is a link |
is_readable() | Checks whether a file is readable |
is_uploaded_file() | Checks whether a file was uploaded via HTTP POST |
is_writable() | Checks whether a file is writeable |
is_writeable() | Alias of is_writable() |
lchgrp() | Changes group ownership of symlink |
lchown() | Changes user ownership of symlink |
link() | Creates a hard link |
linkinfo() | Returns information about a hard link |
lstat() | Returns information about a file or symbolic link |
mkdir() | Creates a directory |
move_uploaded_file() | Moves an uploaded file to a new location |
parse_ini_file() | Parses a configuration file |
parse_ini_string() | Parses a configuration string |
pathinfo() | Returns information about a file path |
pclose() | Closes a pipe opened by popen() |
popen() | Opens a pipe |
readfile() | Reads a file and writes it to the output buffer |
readlink() | Returns the target of a symbolic link |
realpath() | Returns the absolute pathname |
realpath_cache_get() | Returns realpath cache entries |
realpath_cache_size() | Returns realpath cache size |
rename() | Renames a file or directory |
rewind() | Rewinds a file pointer |
rmdir() | Removes an empty directory |
set_file_buffer() | Sets the buffer size of an open file |
stat() | Returns information about a file |
symlink() | Creates a symbolic link |
tempnam() | Creates a unique temporary file |
tmpfile() | Creates a unique temporary file |
touch() | Sets access and modification time of a file |
umask() | Changes file permissions for files |
unlink() | Deletes a file |
只要用 if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。