Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.



Add comment:
Name:
Email:
Comment: *
(Use BBcode - No HTML)


You MUST answer this simple math equation - to prevent spammers: 2 + 18 =  


How can I execute commands on mysql using a php script?

Last updated: 07/02/2009
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.




Powered by KnowledgebasePublisher 1.1
Superb Internet
Content provided by Roberts WebForge, Inc.