Haifa linux club:PHP lecture
Prev Next


opening MySQL DataBase


This is how we open and close a MySQL database:
<?php
    $link 
mysql_connect("mysql_host""mysql_login""mysql_password")
        or die (
"Could not connect");
    print (
"Connected successfully");
    
mysql_select_db ("my_database")
        or die (
"Could not select database");
    
    
$query "SELECT * FROM my_table";
    
$result mysql_query ($query) or die ("Query failed");
    
// This is where we proccess the data returned by the quary

    
mysql_close($link);
?>

mysql_num_fields($result) - Get number of fields in result
mysql_num_rows($result) - Get number of rows in result

mysql_fetch_row($result) - Get a result row as an enumerated array
mysql_fetch_array($result) - Fetch a result row as an associative array.




HOME