Welcome to PCCS-Linux.COM Hello, and welcome to the PCCS-Linux Home Page.
Your last visit was !!!
Your Browser is running on Other
 
PHP Mysql Functions

There are a whole slew of mysql_ functions available to the PHP Programmer.

The functions that I myself use the most are;

        mysql_connect(); or mysql_pconnect();
        mysql_select_db();
        mysql_query();
        mysql_fetch_array();
        mysql_error();
        

Using some of the above functions

Creating a connection to the database, select a database and run a query;

<?
$conn = mysql_connect("localhost","userid","password") or DIE("Unable to
Connect to Server");
        
mysql_select_db("dbname") or DIE("Failed to Connect to Database");
        
$query = "SELECT * from tablename";

$res = mysql_query($query) or DIE("Failed to run Query");
?>

99% of the time I use the following code to do error reporting. Found this code playing with PHPgen
<?

$verbose_queries=0;

function mysqlquery($db_name,$query) {
global $verbose_queries;
        if($verbose_queries !=0)
        echo $query . "<BR*>";
        $result = mysql($db_name,$query);
        return $result; 
}
// I call this function like this

$db_name = "databasename";
$conn = mysql_connect("localhost","username","password");
$_query = "SELECT * from tablename";

$res = mysqlquery("$db_name","$query");
        if(!empty($res) {
        // Do something or nothing
        } else {

        echo mysql_error() . "<BR>";
}



?>

>> Comments/FeedBack


Page hits 75 last request on :12:45



This web site is prepared and maintained by Chauncey Thorn.
The information contained in this site was valid at the time of posting.
Chauncey Thorn, assumes no liability for damages incurred directly or indirectly as a result of errors, omissions or discrepancies.

Remember most of the content here are my notes...

All logos and trademarks in this site are property of their respective owner. All the rest © by PCCS-Linux.COM

PCCS-Linux.COM ::ource Advocate Articles catalogue
2000 2002