PHP:Databases

From wiki
Revision as of 16:45, 10 June 2019 by Hdridder (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport) or die ('Error connecting to mysql');
Open database connection
$result = mysqli_query($conn,$query) or die('Error, retrieve failed');
Execute a query on the opened connection
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
Fetch a row as hash
$row = mysqli_fetch_array($result, MYSQLI_NUM);
Fetch a row as array
mysqli_free_result ($result)
$result->free_result()
Free the memory for the result (use whenever possible)
info = $result->fetch_fields()
info = mysqli_fetch_fields($result)
Get field information from the last query
$info = $result->fetch_fields();
foreach ($info as $val) {
            printf("Name:      %s<br>",   $val->name);
            printf("Table:     %s<br>",   $val->table);
            printf("Max. Len:  %d<br>",   $val->max_length);
            printf("Length:    %d<br>",   $val->length);
            printf("charsetnr: %d<br>",   $val->charsetnr);
            printf("Flags:     %d<br>",   $val->flags);
            printf("Type:      %d<br><br>", $val->type);
}