tags: php
<?php
$link=mysqli_connect('localhost','root',”);
mysqli_select_db('abc',$link);
$sql = “select * from book”;
$result = mysqli_query($sql);
while($row = mysqli_fetch_row($result))
{
echo $row['cid'].'::'.$row[1].'<br>';
}
$result = mysqli_query($sql);
while($row = mysqli_fetch_array($result))
{
echo $row['cid'].'::'.$row[1].'<br>';
}
$result = mysqli_query($sql);
while($row = mysqli_fetch_object($result))
{
echo $row->cid.'::'.$row->title.”<br>”;
}
$result = mysqli_query($sql);
while($row = mysqli_fetch_assoc($result))
{
echo $row['cid'].'::'.$row[1].'<br>';
}
?>
Analysis:
mysqli_fetch_row, This function takes a row from the result set as enumerated data, and obtains a row of data from the result set associated with the specified result identifier and returns it as an array. The column of each result is stored in an array unit, and the offset starts from 0. Note that the offset here starts from 0, which means that you cannot use the field name to get the value, you can only use the index to get the value, so the following code cannot get the value:
while($row = mysqli_fetch_row($res)){
echo $row['cid'].'::'.$row[1].”;
} //The value of $row['cid'] here is not available. To
mysqli_fetch_array, Get a row from the result set as an associative array, or a numeric array, or both. In addition to storing the data in the array as a numeric index, you can also store the data as an associative index and use the field name as the key name. In other words, the result he gets is like an array, which can be valued by key or index, so
while($row = mysqli_fetch_array($res)){
echo $row['cid'].'::'.$row[1].”;
}//Here, $row['cid'], $row[1] can get the corresponding value. To
mysqli_fetch_object, As the name suggests, get a row from the result set as an object, and use the field name as an attribute. So the only way to get the value
while($row = mysqli_fetch_object($res)){
echo $row->cid.'::'.$row->title.”";
}
mysqli_fetch_assoc, Get a row from the result set as an associative array, that is to say, this function cannot use the index to get the value like mysqli_fetch_row, only the field name can be used, so
while($row = mysqli_fetch_assoc($res)){
echo $row['cid'].'::'.$row[1].”;
} //$row[1] does not get a value like this
One additional point:
The mysqli_fetch_array function is defined as follows: array mysqli_fetch_array (resource result [, int result_type]), returns an array generated from the rows obtained from the result set, and returns FALSE if there are no more rows. To
The optional second parameter result_type in mysqli_fetch_array() is a constant and can accept the following values: mysqli_ASSOC, mysqli_NUM and mysqli_BOTH. among them:
1、mysqli_fetch_assoc($result)==mysqli_fetch_array($result,mysqli_ASSOC);
2、mysqli_fetch_row($result)==mysqli_fetch_array($result,mysqli_NUM);
So
The mysqli_fetch_array() function can be regarded as a collection of mysqli_fetch_row() and mysqli_fetch_assoc() to some extent. In addition, mysqli_fetch_array() also has the mysqli_BOTH parameter, which will get an array containing both the association and the numeric index. To
In the sentence $row = $db->fetch_array($query);
$db is a human database operation class, $db->fetch_array($query), fetch_array($query) are methods in that db class, $row = $db->fetch_array( The sentence $query) means to get a row of records in the database from the record set $query. To
can be implemented like this without a class
$conn=@mysqli_connect($host,$user,$pass);
@mysqli_select_db($database,$conn);
$query=mysqli_query($sql);
while($row=mysqli_fetch_array($query)){
$rows[]=$row;
}
| and || both represent or, the difference is that when || encounter multiple conditions, judge from left to right. As long as one condition is true, the entire judgment is considered true, and the re...
The difference between #{} and ${} the difference: contact: Both support @param annotations, specify parameter names, get parameter values. Recommended this way Generally do parameter passing, will us...
for...in 1. Traversing the enumerable properties of an objectName (enumerable: true, passedObject.defineProperty(obj, prop, descriptor) modify, judged by obj.propertyI...
The difference between += and =+ When I was doing LeetCode today, the keyboard knocked faster. Later, the results of the program and the assumptions were very different. So I carefully checked the cod...
I often encounter such a question during the interview: What is the difference between #{} and ${}? The difference between ${} and #{} 1, these two symbols are used in SQL statements, used as placehol...
# {}The difference between ${} By default, using the #{} syntax, MyBatis will generate a PreparedStatement statement and safely set the PreparedStatement parameter, during which MyBatis will perform t...
Here are three tabs <%%>, <%! %>, <%= %>. Here kk from the compiled Servlet to PK under the three differences. <% %> PK <%! %> <% %>: used to pu...
For mutable types of objects “+=” is similar to the .append method, adding an element to the original address location. "=" is similar to reassigning a reference to create an obj...
1 traversing arrays usually with a for loop For ES5, you can also use forEach. ES5 has traversal array functions, such as map, filter, some, every, reduce, reduceRight, etc., but their return results ...
Everything is an object in Python. The three basic elements of an object in Python are: id (identity), type (data type), and value (value). If the comparison between objects is equal, you can use == o...