Skip to content

Instantly share code, notes, and snippets.

@Raffaello
Last active January 17, 2018 16:01
Show Gist options
  • Save Raffaello/b7b1b0b73bd776925020eafc8aaf1ff4 to your computer and use it in GitHub Desktop.
Save Raffaello/b7b1b0b73bd776925020eafc8aaf1ff4 to your computer and use it in GitHub Desktop.
mysql_field_type comparison with type of msqli
<?php
// parameters, set them properly based on your needs.
$host = '';
$username = '';
$password = '';
$query = 'select * from [table] limit 0';
$c = mysql_connect($host, $username, $password);
$r = mysql_query($query, $c);
$n = mysql_num_fields($r);
$fieldType=[];
for($i=0; $i<$n; $i++) {
$fieldType[]=mysql_field_type($r, $i);
}
mysql_free_result($r);
mysql_close($c);
$c = mysqli_connect($host, $username, $password);
$r = mysqli_query($c, $query);
$n = mysqli_num_fields($r);
$fieldiType=[];
for ($i=0; $i<$n; $i++) {
$fieldiType[]=mysqli_fetch_field_direct($r, $i)->type;
}
mysqli_free_result($r);
mysqli_close($c);
assert(count($fieldType) === count($fieldiType));
for($i=0; $i<$n; $i++) {
echo "$i. mysql_type: {$fieldType[$i]} --- mysqli_type: {$fieldiType[$i]}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment