簡體   English   中英

如何將表名轉換為變量?

[英]How to turn table names into variables?

我正在嘗試獲取數據庫中表的列表,並將這些名稱轉換為變量,但是無論我嘗試執行什么操作,都會收到“意外的T_LNUMBER,期望為T_VARIABLE”錯誤。 這是有問題的部分:

$result1 = mysqli_query($connection, "SHOW TABLES LIKE '%".$date3."%'");
$row1 = mysqli_fetch_row($result1); 

if (isset($row1[0])) {  $01 = $row1[0];} 
if (isset($row1[1])) {  $02 = $row1[1];}

我究竟做錯了什么?

發生錯誤是因為PHP變量不能以數字開頭,只能以字母或下划線開頭。

如果要遵循當前的命名約定,請嘗試使用$ one代替$ 01

編輯

鏈接到文檔: http : //php.net/manual/zh/language.variables.basics.php#language.variables.basics

// you can try following one to
$result1 = mysqli_query($connection, "SHOW TABLES LIKE '%".$date3."%'");
$row1 = mysqli_fetch_row($result1); 
//$$row1[0] will create a variable with table name
//if $row1[0] hold the value user then $$row1[0] is the variable $user and you can access in below the declaration 
if (isset($row1[0])) {  $$row1[0] = $row1[0];} 
if (isset($row1[1])) {  $$row1[1] = $row1[1];}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM