classes:general:dbsamples:php_mysql
                Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| classes:general:dbsamples:php_mysql [2017/01/20 02:51] – created localadmin | classes:general:dbsamples:php_mysql [2017/03/21 11:23] (current) – localadmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== PHP example for Postgres | + | ====== PHP example for MySQL database connection ====== | 
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | <?php | ||
| + | |||
| + | // Make a connection to the database | ||
| + | // the values here MUST BE CHANGED to match the database and credentials you wish to use | ||
| + | $mysqli = new mysqli(" | ||
| + | if ($mysqli-> | ||
| + | { | ||
| + | echo " | ||
| + | } | ||
| + | |||
| + | // Define the SQL query, replace table name and column names as necessary | ||
| + | $sql = " | ||
| + | |||
| + | // Execute the query | ||
| + | $result = $mysqli-> | ||
| + | |||
| + | // If the $result variable is not defined, there was an error in the query | ||
| + | if !($result) | ||
| + | { | ||
| + | echo "Query execution failed: (" . $mysqli-> | ||
| + | } | ||
| + | |||
| + | // Iterate through each row of the result | ||
| + | while($row = $result-> | ||
| + | { | ||
| + | // Write HTML to the page, replace this with whatever you wish to do with the data | ||
| + | echo $row[0]."< | ||
| + | } | ||
| + | |||
| + | // Free result set | ||
| + | $result-> | ||
| + | |||
| + | // close connection | ||
| + | $mysqli-> | ||
| + | ?> | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | </ | ||
classes/general/dbsamples/php_mysql.1484880668.txt.gz · Last modified:  by localadmin
                
                