0

I have tried all sorts of things to get a table renamed from php, including mysqli (code below) and mysql_connect/mysql_query. I have tried rename table and alter table. In the example below there are no errors when I execute it. However, when I go look, the 'trac' table is still there with no '2' at the end.

$link = mysqli_connect("lamp1", "user", "pw", "db");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
if ($stmt = mysqli_prepare($link, "rename table trac to trac2")) {
 mysqli_stmt_execute($stmt);
}
else
 echo "error";

This is xampp (recent version) on a Windows Server 2008 machine. Mysql 5.0.7, php 5.3.4.

I can rename the table with no issue through phpMyAdmin!

What can I check / try? Is there a log file I can turn on / look at to see whats happening from the mysql side?

2
  • Are you getting "error" as a result of your script? Throw a echo mysqli_stmt_error($stmt); right after the execute (inside the if)
    – Aaron
    Aug 4, 2011 at 20:08
  • Well, ultimately mysqli_stmt_error($stmt); solved it for me. I think between my different tests I may have had some 'table already exists' or other errors and now that I could see the errors, I was able to work it all out. Ultimately my code above was correct. Aug 5, 2011 at 0:23

2 Answers 2

0

Use mysqli_stmt_error($stmt) to figure out the error that is being returned, and then act on that.

1

citing from the MySQL manual

When you execute RENAME, you cannot have any locked tables or active transactions. You must also have the ALTER and DROP privileges on the original table, and the CREATE and INSERT privileges on the new table.

So it is very likely that the user user does not have the correct privileges.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .