Following is a typical OOP way to Connect and Retrive data from MySQL database using MySQLi and PHP. Now I am a little bit confused on using the pure PHP arrays at this example:
Can some one please let me know if the $result is array or not? I mean in
$result = $mysqli_coonect->query($sql);
if so how come we didn't use the array() function or [] to create it?!
same thing happening with $row at:
$row = $result->fetch_assoc()
I am asking this because in order to load $row; to $results[] at $results[] = $row; we declared the $results as an array explicitly before the while() how come we are not doing this for other or vice versa?!
<?php
$mysqli_coonect = new mysqli($host_name, $user_name, $pass_word, $database_name, $port);
$sql = "SELECT * FROM books WHERE id <= 10";
$result = $mysqli_coonect->query($sql);
if (($result) && ($result->num_rows > 0))
{
$results = array();
while ($row = $result->fetch_assoc())
{
$results[] = $row;
}
$result->free();
}
$mysqli_coonect->close();
array()isn't technically a function -- it's one of those syntax oddities, like many other 'language constructs' which are specifically not-functions, but look like them (e.g.list())array()looks like, and is occasionally referred to as a function is more a historical quirk than anything else. If you try and use it like it's a function, you're going to have a bad time. php.net/manual/en/…