PHP MYSQL 组合的转换问题


Casting Issue with PHP MYSQL Combination

我想我在铸造方面有问题。

$db = mysqli_connect('127.0.0.1','root','password','test');
if (! $db) { die("Can't connect: " . mysqli_connect_error( )); }
$new_table = $_POST["newtablename"];
$old_table = $_POST["oldtablename"];
$numberRows = $_POST["numberrows"];
$startRow = $_POST["startrow"];
$counter = 0;
drop_table($db, $new_table);
create_table($db, $new_table);
for($counter = 0; $counter < $numberRows; $counter += 1)
{
   $currentRow = getRow($db, $old_table);
   $ID = $currentRow(1);
   $Partner = $currentRow(2);
   $Merchant = $currentRow(3);
}
function getRow($db, $old_table)
{
    $select = "SELECT ID, Partner, Merchant FROM " .$old_table;
    $q = mysqli_query($db, $select);
    $row = mysqli_fetch_row($q);
    return $row;
}

 function create_table($db, $new_table){
    $create = "CREATE TABLE " .$new_table. "(ID INT, Partner VARCHAR(20), Merchant       VARCHAR(30))";
    $q = mysqli_query($db, $create);
} 
 function drop_table($db,$new_table){
     $drop = "DROP TABLE IF EXISTS " .$new_table;
     $q = mysqli_query($db, $drop);
     } 

这是我得到的错误

致命错误:函数名称必须是第 26 行 C:''xampp''htdocs''myfiles''mysqli_combined_functions.php 中的字符串

第 26 行是我设置 $ID = $currentRow(1) 的地方。我的印象是该行将作为变量数组返回,并且使用正确的数字可以访问我想要的变量。假设这是真的(如果不是,请告诉我),那么我认为它正在以 INT 的形式读取 ID,这就是我拥有的 SQL 表中的内容。有人可以帮我把它扔成绳子吗?或者也许我完全错过了问题?

使用方括号访问数组的元素。

$currentRow[1]

请记住,第一个索引也将是 0。

不强制转换。这些是数组索引,请注意方括号。[]

   $currentRow = getRow($db, $old_table);
   $ID = $currentRow[1];
   $Partner = $currentRow[2];
   $Merchant = $currentRow[3];