Post Reply  Post Thread 
Running MySQL Commands in a PHP Script
freesouljah
Junior Member
**

Posts: 27
Group: Registered
Joined: Jun 2006
Status: Offline
Reputation: 0
Post: #1
Question Running MySQL Commands in a PHP Script

I notice in phpMyAdmin that it has an option to "Create PHP Code." How can I use this to make a php script to run a mysql command through my browser when I put in the url?

thanks Icon_v


06-16-2006 07:11 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pacifier
Administrator
*******

Posts: 222
Group: Administrators
Joined: May 2006
Status: Offline
Reputation: 1
Post: #2
RE: Running MySQL Commands in a PHP Script

You should google for a tutorial on PHP and MySQL and learn the basics of connecting to MySQL and executing a query. It's really very very easy and you should learn it in minutes.

It should go like this:

1. PHP starting tag:

<?php

2. Connect to mysql: (set connection handler as $db)

$db = mysql_connect("localhost", "username", "password");

3. Select mysql database:

mysql_select_db("database_name");

4. Execute the query (ONLY ONE query can be executed here).. You can use multiple mysql_query() functions to execute more:

mysql_query("INSERT INTO blah blah...");

5. Close mysql connection after executing all the queries:

mysql_close($db);

6. Output a dummy message:

echo "Done!";

Wrapped up code:

PHP Code:
<?php

$db 
mysql_connect("localhost""username""password");
mysql_select_db("database_name");

mysql_query("INSERT INTO blah blah...");

mysql_close($db);

echo 
"Done!";

?>

06-18-2006 01:20 PM
Find all posts by this user Quote this message in a reply
freesouljah
Junior Member
**

Posts: 27
Group: Registered
Joined: Jun 2006
Status: Offline
Reputation: 0
Post: #3
RE: Running MySQL Commands in a PHP Script

yeah...that is really simple...for some reason I thought it would take more than that...

thanks Big Grin


06-19-2006 06:13 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: