Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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 '11 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. –  Scott Szretter Aug 5 '11 at 0:23

2 Answers 2

up vote 0 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.