Php dataset operation methods 1. mysql_unbuffered_query () returns results while querying, and does not cache the results on the page. This method is suitable for Big Data Processing. after use, the dataset is automatically destroyed. you can no longer use mysql_data_set ($ result, count) to locate the revelation position of the midstream mark in the dataset. End of mysql_unbuffered_query Query
Php dataset operation methods 1. mysql_unbuffered_query () returns results while querying, and does not cache the results on the page. This method is suitable for Big Data Processing. after use, the dataset is automatically destroyed. you can no longer use mysql_data_set ($ result, count) to locate the revelation position of the midstream mark in the dataset. End of mysql_unbuffered_query Query
Several ways to operate datasets in php
1. mysql_unbuffered_query ()
The query results are provided while not cached on the page. This method is suitable for Big Data Processing. After the data is used, the dataset is automatically destroyed.
- You can no longer use mysql_data_set ($ result, count) to locate the revelation position of the midstream mark in the dataset.
- The number of rows in the result set queried by mysql_unbuffered_query is similar to that in mysql_fetch_array. You cannot use mysql_num_rows to obtain the number of rows in the result set.
- The number of rows in the result set of mysql_unbuffered_query query is similar to that of mysql_fetch_array. You can use mysql_num_rows to obtain the number of rows in the result set.
- Then, use a function similar to mysql_fetch_array to operate the dataset. The number of rows in the dataset is 0 and no output is made.
Ii. mysql_query ()
All the query results are stored in the cache for convenient operations with a small amount of data.
- Mysql_fetch_array functions can obtain the correct number of data rows during the operation or after the operation is completed.
- Mysql_data_set ($ result, count) allows you to operate the following table of a dataset at any location.
- Mysqli_free_result ($ result); after clearing the query set in the memory, it is the same as mysql_unbuffered_query ().
Demo:
Column child: The highlighted red part is the key comparison code
1
$ Mysql_dbname indicates the current caller's dbname 10 11 */12 13 14 15 header ("Content-Type: text/html; charset = UTF-8 "); 16 17 18 19 class DbConn {20 21 22 23 private $ mysql_host; // connected host 24 25 private $ mysql_user; 26 27 public $ mysql_pwd; 28 29 private $ mysql_language; // database encoding language 30 31 private $ mysql_conn; // Mysql connection object 32 33 private $ db_select; // The selected database object 34 35 36 37 public $ mysql_dbname; // select the database to connect to 38 39 public $ sqlstr; // SQL statement 40 41 public $ error; // error message: 42 43 44 45 function DbConn () {46 47 $ this-> mysql_host = "localhost"; 48 49 $ this-> mysql_user = "root"; 50 51 $ this-> mysql_pwd = "sasa "; 52 53 $ this-> mysql_language = "UTF8"; 54 55 $ this-> mysql_conn = NULL; 56 57 $ this-> db_select = NULL; 58 59 $ this-> sqlstr = ""; 60 61 62 63} 64 65 66 67 // set error message 68 69 private function SetError ($ errormsg) 70 71 {72 73 $ this-> error + ="
"+ $ Errormsg; 74 75} 76 77 78 79 public function ShowError () 80 81 {82 83 return $ this-> error; 84 85} 86 87 88 89 90 91 // Connect to mysql 92 93 public function Connect () 94 95 {96 97 $ this-> mysql_conn = mysql_connect ($ this-> mysql_host, $ this-> mysql_user, $ this-> mysql_pwd) or die ("mysql connection error"); // mysql connection 98 99 $ this-> SetError (mysql_error ()); 100 101 // select the connected database name 102 103 $ this-> db_select = mysql_select_db ($ thi S-> mysql_dbname) or die ("no database permission or database selection error"); 104 105 $ this-> SetError (mysql_error ()); 106 107 mysql_query ("set names 'utf8'"); // Code Conversion 108 109} 110 111 112 113 // disable connection 114 115 public function CloseCon () 116 117 {118 119 mysql_close ($ this-> mysql_conn); 120 121} 122 123 124 125 // query method 126 127 public function SelectAll () 128 129 {130 131 $ result = mysql_query ($ this-> sqlstr, $ this-> mysql_conn); 132 133 if ($ result) 13 4 135 {136 137 // $ result_row = mysqli_fetch_array ($ result); 138 139 // mysql_fetch_row () returns the next row in the result set. If no more rows exist, FALSE is returned. 140 141 // mysql_fetch_array () returns the key value or array in the result set. If no more rows exist, FALSE is returned. 142 143 while ($ result_row = mysql_fetch_array ($ result) 144 145 {146 147 $ userid = $ result_row ["userid"]; 148 149 $ username = $ result_row ["username"]; 150 151 $ userpwd = $ result_row ["userpwd"]; 152 153 $ useremail = $ result_row ["useremail"]; 154 155 156 157 echo""; 158 159 echo"Username id:$ Userid"; 160 161 echo"User name:$ Username"; 162 163 echo"Password:$ Userpwd"; 164 165 echo"Email:$ Useremail"; 166 167 echo""; 168 169 echo"
"; 170 171 172 173 // mysqli_free_result ($ result ); clear the in-memory query set 174 175} 176 177 178} 179 180 181 182 // Big Data Query verification differences between the two query datasets 183 public function Select () 186 187 {188 189 // cancel mysql_unbuffered_query and mysql_query respectively to view the effect 190 191 $ result = mysql_unbuffered_query ($ this-> sqlstr, $ this-> mysql_conn ); 192 193 // $ result = mysql_query ($ this-> sqlstr, $ this-> mysql_conn); 194 195 196 197 if ($ result) 198 199 {200 201 // $ Result_row = mysqli_fetch_array ($ result); 202 203 // mysql_fetch_row () returns the next row in the result set. If no more rows exist, FALSE is returned. 204 205 // mysql_fetch_array () returns the key value or array in the result set. If no more rows exist, FALSE is returned. 206 207 while ($ result_row = mysql_fetch_array ($ result) 208 209 {210 211 $ userid = $ result_row ["userid"]; 212 213 $ username = $ result_row ["username"]; 214 215 $ userpwd = $ result_row ["userpwd"]; 216 217 $ useremail = $ result_row ["useremail"]; 218 219 220 221 echo""; 222 223 echo"Username id:$ Userid"; 224 225 echo"User name:$ Username"; 226 227 echo"Password:$ Userpwd"; 228 229 echo"Email:$ Useremail"; 230 231 echo""; 232 233 echo"
"; 234 235 echo" obtain the total number of data sets during processing: "; 236 237 // mysql_unbuffered_query query result set; During mysql_fetch_array processing, you cannot use mysql_num_rows to obtain the number of rows in the result set. 238 239 echo mysql_num_rows ($ result); 240 241 echo"
"; 242 243 244 245} 246 247 mysql_data_seek ($ result, 1); // point the pointer to the result set of the first 248 249 // mysql_unbuffered_query query. After mysql_fetch_array is processed, you can use mysql_num_rows to obtain the number of rows in the result set. 250 251 echo "after processing is complete, the total number of rows in the dataset is obtained:"; 252 253 echo mysql_num_rows ($ result); 254 255 echo"
"; 256 257 258 259 260 261 // re-operate the result set of the mysql_unbuffered_query query. If the data set is null, no 262 while ($ result_row = mysql_fetch_array ($ result) is output )) 264 265 {266 267 $ userid = $ result_row ["userid"]; 268 269 $ username = $ result_row ["username"]; 270 271 $ userpwd = $ result_row ["userpwd"]; 272 273 $ useremail = $ result_row ["useremail"]; 274 275 276 277 echo""; 278 279 echo"Username id:$ Userid"; 280 281 echo"User name:$ Username"; 282 283 echo"Password:$ Userpwd"; 284 285 echo"Email:$ Useremail"; 286 287 echo""; 288 289 echo"
"; 290 291 292 293 // mysqli_free_result ($ result); clear the query set in memory 294 295} 296 297 echo" the number of rows after reprocessing is :"; 298 299 echo mysql_num_rows ($ result); 300 301 mysql_free_result ($ result); 302 303 304 305}
306}
307}
I wrote my blog for the first time. I hope you can criticize and correct me more. I also want php to operate on the excellent database framework. I have just changed from. net to php, but I don't know much about it. I hope I can get more information.