$conn = mysqli_connect($hostname, $username, $password,$database) or trigger_error(mysql_error(),E_USER_ERROR);) |3 e3 ~' u' G, k
mysqli_query($conn ,"SET NAMES utf8"); * W- J. B) G* P& N
+ j( ]" V& Z5 E/ y6 a" P
$sql = "select count(*) as total from " . "table_name"; ) i4 m% ~: z5 R) |" t: [7 d1 V7 ^; M: |
$rec = mysqli_fetch_assoc(mysqli_query( $conn,$sql)); ; n' t9 T: W% H0 H+ B; p% ~; M* j9 I
echo $rec['total']; 7 W: ]: T; P$ s+ ?, G1 V
mysqli_close($conn);+ R+ L; p. {2 R2 o
?>
複製代碼
[hide=d100000000000000000000,999999999999]於video1主機下 /test/connectmysql8.php[/hide]4 b- d0 G- X. N* A8 c5 G
# N7 Q) @) B( W9 U/ E+ [3 v( J O! |% Q# t# U2 o' \
當php 7.2.24 connect to mysql server,出現 :
PHP Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:97 h( S' M8 J V, u, H: O) Q
Stack trace: 9 S$ q; W6 U: A# u
#0 {main} 9 R0 l X ?. O( B2 V
thrown in /test/connectmysql8.php on line 9. W8 T3 T0 B% U) v1 V& M! e, ~
& D2 t% W. `' a0 L4 u' K) ~
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /test/connectmysql8.php:9 $ a) v3 p% K& u4 o
Stack trace: _# v6 x4 V( B# V) G: |( A
#0 {main} % ~& B& E* J) i, ]- l$ Z, \/ j
thrown in /test/connectmysql8.php on line 9
複製代碼
這是版本相依的問題,只要 yum install php-mysqlnd 或 yum install php-mysqli 即可 - d0 G/ h! L+ r+ W { 2 K( n5 P3 O' u7 v2 V 4 g" {* g5 v9 [: J7 M[Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.) ^ I, L0 _+ k
說明: 千萬不能照它建議用"UTF8MB4",否則無法成功啟動; L% G4 q$ x a
7 n, s% C# V, \6 m: D(2)! ], \( w3 p" b B
(1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'system>0' at line 1 7 A; X) ?, K n. P u) A; Z2 y9 Q! bSELECT COUNT(*) FROM common_usergroup WHERE type='special' and system>0! ~; Y% v9 k, Z, J% m
M$ B$ U( {% L& T(1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORD' at line 1, j. F3 }6 T* t1 \! m* Q
SELECT * FROM forum_announcement WHERE type!=2 AND groups = '' AND starttime<=1532077291 AND (endtime>=1532077291 OR endtime=0) ORDER BY displayorder, starttime DESC, id DESC LIMIT 1 # R$ {3 f6 m9 O: f( V: q! R; N: v. Q% t: X: G5 `3 V
因為MySQL 8.0+將system和groups作為了關鍵字,所以不能直接在SQL中將system和groups這兩個詞作為數據庫、數據表、數據表字段中的任意一種使用,如果數據庫名或數據表名或數據表字段名使用了system或groups作為名字,必須使用一對反引號引用起來。寫作`system`或`groups`。 . t* t7 D' n, a9 f 6 H: b: X$ x7 N, l" \- D第一個錯誤需要找到Discuz!目錄中的source\class\table\table_common_usergroup.php, 6 Z3 a* b1 V: s$ ^將文件中所有的system全部改成`system`,保存後重新上傳到服務器的相同目錄即可。 7 q3 ^7 y9 G8 p- C7 c 5 f6 U, x$ ?' N) Z第二個錯誤需要找到Discuz!目錄下中的source\class\table\table_forum_announcement.php, ' }6 }9 t8 r3 \' q; w& r/ T. t將文件中所有的groups全部改為`groups`,保存後重新上傳到服務器的相同目錄即可。 3 Q" b% Z; y- a8 _( s4 x- l5 s: B( m5 ~( a
如果在MySQL 8+環境下安裝Discuz!,在安裝前需要給install\data\install.sql文件中沒有加引號的所有system逐一添加一對反引號保存重新上傳到服務器的相同目錄,否則也會出現SQL語法錯誤。 / j$ H/ `, X4 R2 s% c5 l V" Y5 t- v* S# K$ N9 n9 d9 O; c
為了避免語法錯誤,在寫SQL語句時,一定要為所有的數據庫名、數據表名、數據表字段名全部添加一對反引號,像Discuz!這樣的寫法是很不妥的。 + I# H) b9 m3 y' b2 k8 y以上參考: 升級到 MySQL 8.0+ 後Discuz! 更新緩存時出現SQL語法錯誤6 i3 J4 p. X" [6 K% A$ }6 T
?) o# |; a; n$ R) X* x1 G/ J' m+ q' ]& L+ F4 |
9 r% K' X2 A& \ z. U4 A' B# e; s& l) _1 ]1 z( p/ H