init(); /* connect to MySQL server */ $cxn->real_connect ($host, $user, $password, $dbname, $port, $socket) or die ('Could not connect to the database server' . mysqli_connect_error()); $query = "SELECT * FROM City"; /* execute the query */ if ($cxn->real_query ($query)) { /* initiate the result set retrieval */ if ($result = $cxn->store_result()) { /* find the number of rows in the result set */ $nrows = $result->num_rows; echo "\nRetrieved $nrows row(s).\n\n"; echo "CityName\n--------\n"; while ($row = $result->fetch_assoc()) { $data1 = $row["CityName"]; echo "$data1\n"; } } /* close the result set */ $result->close(); } /* close the database connection */ $cxn->close(); ?>