PHP:Databases: Difference between revisions
Jump to navigation
Jump to search
Created page with "Category:PHP ;$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname, $dbport) or die ('Error connecting to mysql'); :Open database connection ;$result = mysqli_query($..." |
No edit summary |
||
| Line 8: | Line 8: | ||
;$row = mysqli_fetch_array($result, MYSQLI_NUM); | ;$row = mysqli_fetch_array($result, MYSQLI_NUM); | ||
:Fetch a row as array | :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 | |||
<syntaxhighlight lang=php> | |||
$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); | |||
} | |||
</syntaxhighlight> | |||
Latest revision as of 14:45, 10 June 2019
- $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);
}