This shows you the differences between two versions of the page.
| — |
howto_extract_data_from_db_in_php [2012/03/09 10:43] (current) |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | Creating a simple PHP SQL database extractor. | ||
| + | Example: Fetching data from X.X.X.X is the ip address of the db server. | ||
| + | |||
| + | < | ||
| + | |||
| + | HTML | ||
| + | |||
| + | BODY | ||
| + | |||
| + | <?php | ||
| + | $con = mysql_connect(" | ||
| + | if (!$con) | ||
| + | { | ||
| + | die(' | ||
| + | } | ||
| + | |||
| + | mysql_select_db(" | ||
| + | |||
| + | $result = mysql_query(" | ||
| + | information_schema.COLUMNS WHERE table_name LIKE ' | ||
| + | |||
| + | while($row = mysql_fetch_array($result)) | ||
| + | { | ||
| + | echo $result[' | ||
| + | echo "< | ||
| + | } | ||
| + | |||
| + | mysql_close($con); | ||
| + | ?> | ||
| + | |||
| + | </ | ||
| + | |||
| + | END BODY | ||
| + | |||
| + | http:// | ||
| + | |||
| + | < | ||
| + | If you do not know tables you can have the db describe them using the following command: | ||
| + | |||
| + | Definition: The describe SQL command is used to list all of the fields in a table and the data format of each field. | ||
| + | |||
| + | It is phrased as: describe [TableName]; | ||
| + | |||
| + | Examples: This would list all of the fields and their formats for the table called ' | ||
| + | |||
| + | describe Colors; | ||
| + | |||
| + | DESCRIBE ; | ||
| + | |||
| + | or | ||
| + | |||
| + | SELECT column_name, | ||
| + | table_schema='' | ||
| + | |||
| + | |||
| + | SELECT table_name, | ||
| + | information_schema.COLUMNS WHERE table_name LIKE ' | ||
| + | ORDER BY ordinal_position | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | < | ||
| + | |||
| + | <!-- AddThis Button BEGIN --> | ||
| + | <a class=" | ||
| + | <!-- AddThis Button END --> | ||
| + | <br> | ||
| + | <br> | ||
| + | </ | ||
| + | |||
| + | Share this knowledge with your friends! | ||