Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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