MyBB Community Forums

Full Version: Need to run some sql querys without access to sql workspace.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am currently working on fixing something wrong with my phpmyadmin on my dedicated server at the moment, because its broken.

In the mean time, I need to do the following things:

- Rename a column
- Clear a column

What I need to do is clear the Registrations IP column in the users table.

And then after that, I need to rename it, and then change the way that registration ips are stored, which I assume is in member.php, unless you guys did something else with it.

Anyways can someone get me a php file or something with the code to do these things where I can simply run those 2 commands?

Thank you.
Try this:
<?php 
require_once ("inc/functions.php");

$database = "data_base_name";
$username = "phpMyAdmin_user_name";
$password = "phpMyAdmin_password";
$prefix = "database_prefix";

$mysqli = new mysqli("localhost", $username, $password, $database);
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo "host info: ".$mysqli->host_info . "<br /><br />"; 

$sql = "UPDATE `{$prefix}users` SET `regip`='' WHERE 1";
if (!$mysqli->query($sql))
{
    die("first query not executed");
}

$sql = "ALTER TABLE `{$prefix}users` CHANGE `regip` `newname` varbinary(16)";
if (!$mysqli->query($sql))
{
    die("second query not executed");
}
echo "executed successfully";

  1. Set the 4 variables at the start according to your inc/config.php file and fill in the new name of the regip column (newname) in the second $sql = statement;
  2. Store the file (e.g. test.php) in the root of your forum;
  3. Run it by  root_url/test.php;
I tested it with other queries and these worked.

PS
I think the require_once statement is not necessary in this case (it was there in the old script I used as a template where it was necessary indeed because then I used MyBB functions). In that case you can delete the statement and run the script from everywhere you want.