Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can sql's DESC be run from a PHP script?

Status
Not open for further replies.

peterv6

Programmer
Sep 10, 2005
70
US
I want to run the sql command DESC from within a php script. I'm new to this, and am not sure that this is possible. My attempt below runs with no errors, but gives no output. Can someone help me out with this? Any help is gratefully appreciated!
PV


<?php
// Thursday, August 14, 2008 6:43:54 PM
// Connect to port 4444 on vanderhaden.net.
$link = mysql_connect('vanderhaden.net:4444', 'peterv', 'testpw','testdb');
if (!$link) {
printf("Connect failed: %s\n", mysql_error());
exit();
} else {
// select the database
$db_selected = mysql_select_db('testdb', $link);
if (!$db_selected) {
die ('Can\'t use testdb: ' . mysql_error());
}
$query ="DESC leadsTable";
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
}
?>



PETERV
Syracuse, NY &
Boston, MA
 
You don't appear to be doing anything to display $result.

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
I think this might be time to slow down and review what you know and what you still have to learn.

You realize that you're dealing with (at least) three languages, mySQL for communicating with the database and php to process your code and HTML to display your code in the website. In order for you to start seeing some results, you have to understand the basics of all three languages.

Your mySQL command asks for description of a table.

Your php script executes that command on the selected database and put the result in a variable.

That's where your script ends. If you want any output, your php script will have to extract information from the variable where the result has been put and output it as a text (or eventually HTML).

I strongly suggest you read the page on mysql_fetch_* series of functions to see what steps you need to go through from initially connecting to a database to a final output in the browser.

P.S. If the username and password you provided in the above script are those of your server, I suggest you red flag your post and alert the site management to remove them. No need to post your actual usernames and passwords on a public internet site. :)

___________________________________________________________
[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top