arunpatal Posted February 22, 2014 Share Posted February 22, 2014 Hi, I am trying to create a table via foreach loop $mysqli = ""; $mysqli .= "mysqli_query($new_con,'CREATE TABLE IF NOT EXISTS $main_table("; foreach ($fields as $field_name => $field_value): @$field_type = @$type[$field_name]; $mysqli .= "$field_value $field_type,"."<br>"; endforeach; $mysqli .= "$fields[0] INT AUTO_INCREMENT PRIMARY KEY"; $mysqli .= ")')"; echo $mysqli; But i am getting error Catchable fatal error: Object of class mysqli could not be converted to string in C:\wamp\www\My_Site\install\function.php on line 97 This is 97 line => $mysqli .= "mysqli_query($new_con,'CREATE TABLE IF NOT EXISTS $main_table("; This all code is inside function Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted February 22, 2014 Share Posted February 22, 2014 inside of a double-quoted string, php variables, in this case your $new_con mysqli instance, are replaced with their content and an instance of mysqli has no meaning inside of a string and cannot be converted to a string.the only part you should be building in the $mysqli variable is the actual (my)sql query statement. the code that is going to run that query would be separate and would use the resulting query statement that would be in the $mysqli variable - // build the (my)sql query statement $mysqli = "CREATE TABLE IF NOT EXISTS $main_table ....."; // run the query mysqli_query($new_con,$mysqli); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.