VC9, MySQL5.1我用MySQL的C API, 使用MYSQL_ROW row = mysql_fetch_row(query)子后才发现,row里面的保存的是字符数组。
我就很不明白了,比如一个INT字段在数据库中用4个字节保存整数,调用mysql_fetch_row()的过程中,还要进行Int to char*的转换。而在我的使用中,又要把它还原成Int,这样,中间就有两次白白的转换。
请问有没有直接读取出字段原来类型的API?谢谢
我就很不明白了,比如一个INT字段在数据库中用4个字节保存整数,调用mysql_fetch_row()的过程中,还要进行Int to char*的转换。而在我的使用中,又要把它还原成Int,这样,中间就有两次白白的转换。
请问有没有直接读取出字段原来类型的API?谢谢
// 加载mysqldb类
require_once('./mysqldb.php');
$db = new mysqldb();
$mysqli = &$db->getMysqli();
$sqlquery ="select id,name,startdate,uptime,regtime from test.t1";
// Send a query to the server
if ($result = $mysqli->query($sqlquery)) {
if($result->num_rows > 0){
if($row = $result->fetch_array(MYSQLI_BOTH)) {
print_r($row);
echo "id ->".gettype($row[0])."\n";
echo "name ->".gettype($row[1])."\n";
echo "startdate ->".gettype($row[2])."\n";
echo "uptime ->".gettype($row[3])."\n";
echo "regtime ->".gettype($row[4])."\n";
}
}
}
// Destroy the result set and free the memory used for it
if($result) $result->close();
$db->close();
exit;
?>php tmp.php
Array
(
[0] => 1
[id] => 1
[1] => coolwind
[name] => coolwind
[2] => 2009-05-01
[startdate] => 2009-05-01
[3] => 2009-05-19 08:10:32
[uptime] => 2009-05-19 08:10:32
[4] => 2009-05-19 08:10:32
[regtime] => 2009-05-19 08:10:32
)
id ->string
name ->string
startdate ->string
uptime ->string
regtime ->string