MYSQLI
$mysqli = newmysqli ( "localhost" , "my_user" , "my_password" , "world" ) ;
$result = $mysqli -> query ( "SELECT * FROM table_name" , MYSQLI_USE_RESULT ) ;
if ( $result ) {
while ( $row = $result -> fetch_assoc ( ) ) {
print_r ( $row [ 'Name' ] . PHP_EOL ) ;
}
}
$result -> close ( ) ;
PDO
$dbConfig = array (
'TYPE' => 'mysql' ,
'HOST' => "127.0.0.1"
'NAME' => 'slong' ,
'USER' => 'root' ,
'PWD' => 'root' ,
'PORT' => 3306 ,
) ;
$dsn = "{ $dbConfig [ 'TYPE' ] } :host={ $dbConfig [ 'HOST' ] } ;port={ $dbConfig [ 'PORT' ] } ;dbname={ $dbConfig [ 'NAME' ] } " ;
$dbh = new PDO ( $dsn , $dbConfig [ 'USER' ] , $dbConfig [ 'PWD' ] ) ;
print_r ( $dbh -> getAttribute ( PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY ) ) ;
$dbh -> setAttribute ( PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY , false ) ;
print_r ( $dbh -> getAttribute ( PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY ) ) ;
$result = $dbh -> query ( "SELECT * FROM table_name" ) ;
if ( $result ) {
while ( $row = $result -> fetch ( PDO :: FETCH_ASSOC ) ) {
print_r ( $row [ 'Name' ] . PHP_EOL ) ;
}
}
$dbh = null ;
MYSQL
$conn = mysql_connect ( "localhost" , "my_user" , "my_pass" ) ;
$db = mysql_select_db ( "world" ) ;
$result = mysql_unbuffered_query ( "SELECT * FROM table_name" ) ;
if ( $result ) {
while ( $row = mysql_fetch_assoc ( $result ) ) {
print_r ( $row [ 'Name' ] . PHP_EOL ) ;
}
}