VC9, MySQL5.1我用MySQL的C API, 使用MYSQL_ROW row = mysql_fetch_row(query)子后才发现,row里面的保存的是字符数组。
我就很不明白了,比如一个INT字段在数据库中用4个字节保存整数,调用mysql_fetch_row()的过程中,还要进行Int to char*的转换。而在我的使用中,又要把它还原成Int,这样,中间就有两次白白的转换。
请问有没有直接读取出字段原来类型的API?谢谢

解决方案 »

  1.   

    没有,只能这样。自己进行转换了不过你可以通过API 取到原来这个字段是什么数据类型,然后将row[]中的string 转换成原来的数据。
      

  2.   

    末学测试php得到的数组,也全部都是字符型的,您需要自己转换一下!<?php
        // 加载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
      

  3.   

    呵呵,自己转换一下也不费事,现成的就是这样,除非修改MYSQL的源码
      

  4.   

    楼上的还真提醒了我,可以尝试去看看MYSQL的源代码。如果海量数据需要操作,这样转换来转换去挺划不来的
      

  5.   

    还有一种取数据的方法 mysql_stmt_bind_result