I think I have a problem with casting.
$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);
}
This is the error I get
Fatal error: Function name must be a string in C:\xampp\htdocs\myfiles\mysqli_combined_functions.php on line 26
Line 26 is where I set $ID = $currentRow(1). I am under the impression that the row will be returned as an array of variables, and using the proper number I can access the variable I want. Assuming thats true (let me know if its not) then I think it is reading the ID in the form of an INT which is what it is in the SQL table I have. Can someone help me cast it into string? or perhaps I’m missing the problem completely?
Not casting. These are array indexes, note the square brackets. [ ]