Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function dbConnect(){
- $hostname = 'localhost';
- $username = 'tbcj857';
- $mysql_pass = 'm2d59';
- $database = 'tbcj857';
- $conx = mysql_connect ($hostname, $username, $mysql_pass)
- or die ("Can't connect to MySQL" .mysql_error() );
- mysql_select_db($database)
- or die ("Can't select that database" .mysql_error() );
- return $conx;
- }
- dbConnect();
- $sql = "SELECT * FROM users WHERE id = 3";
- $result = mysql_query($sql) or die(mysql_error() );
- //Now your data is in $result, which is a data type of resource:
- //mySQL_fetch_assoc() fetches data *a row at a time* from a resource as an
- //associative array.
- //We therefore have to loop over the result to get all the rows out,
- //or we would only get the first row. We'll use a 'while' loop to do this:
- //while (condition is ture) {do this code}
- //ie, "as long as there's another row of $result, put it in $row"
- $row = mysql_fetch_row($result);
- //echo '<b>' . $row['fname'] . "'s data: </b><br/>\n";
- foreach ($row as $key => $value){
- //echo "\t";
- echo "$key : $value <br/>";
- }
- //echo "<br/>\n";
- //}
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement