How can I execute commands on mysql using a php script?
Sometimes you want to just execute arbitrary mysql commands on a one time basis against a mysql database. This little script lets you do that, and might be instructional for other scripts.
This one adds a new field to a table.
<?
$sql = "select * from zen_admin";
$host = "localhost";
$user = "username";
$pass = "password";
$db = "database";
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db, $conn);
echo "<pre>";
$r = mysql_query($sql,$conn);
$results = mysql_fetch_array($r, MYSQL_ASSOC);
print_r($results);
mysql_free_result($r);
echo "</pre>";
?>
DONE.