sql >> Database >  >> RDS >> Mysql

Hoe gegevens uit de database ophalen en weergeven in PHP?

<?php
//Connect to DB
$db = mysql_connect("localhst","user","pass") or die("Database Error");
mysql_select_db("db_name",$db);

//Get ID from request
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

//Check id is valid
if($id > 0)
{
    //Query the DB
    $resource = mysql_query("SELECT * FROM table WHERE id = " . $id);
    if($resource === false)
    {
        die("Database Error");
    }

    if(mysql_num_rows($resource) == 0)
    {
        die("No User Exists");
    }

    $user = mysql_fetch_assoc($resource);

    echo "Hello User, your number is" . $user['number'];
}

Dit is erg basic, maar zou je erdoorheen moeten helpen.



  1. Kan parameter niet doorgeven via referentie in MySQLi

  2. Is de id-kolompositie in Postgresql belangrijk?

  3. mysql-queryresultaat in php-array

  4. MySQL REPLACE variabele tekenreeks