在$result=mysql_query($query,$link);
中,$result得到的值是resource id #(数字)
这样的东西,它返回的只是你的记录的标号,并不是什么特定的数据类型
当您用mysql_fetch_row,mysql_fetch_array,mysql_fetch_object时取得的将是以数组类型或者对象类型得到的东东
用list列出后得到的变量比如说$username,$id这些都是原来您的数据库表里面所设定的类型,如果想要得到不同的,可以用函数转换类型--这是后话`
`
中,$result得到的值是resource id #(数字)
这样的东西,它返回的只是你的记录的标号,并不是什么特定的数据类型
当您用mysql_fetch_row,mysql_fetch_array,mysql_fetch_object时取得的将是以数组类型或者对象类型得到的东东
用list列出后得到的变量比如说$username,$id这些都是原来您的数据库表里面所设定的类型,如果想要得到不同的,可以用函数转换类型--这是后话`
`
You must use mysql_real_query() rather than mysql_query() for queries that contain binary data, because binary data may contain the `\0' character. In addition, mysql_real_query() is faster than mysql_query() because it does not call strlen() on the query string. 另外,mysql_real_query 格式:
int mysql_real_query(MYSQL *mysql, const char *query, unsigned int length)例子: (重点是/******/之间夹的部分)#include <stdio.h>
#include <mysql.h>unsigned char *getval(unsigned char *);main()
{
/*
CGI backend example that does simple
data base lookup.
*/ char *place;
char sqlbuff[256]; /* hope it's big enough ! */
int err = 0;
int nrows;
MYSQL dbase;
MYSQL_RES *result; printf("Content-type: text/html\n\n");
printf("<html><head><title>CGI C Example #3</title></head>\n");
printf("<body><h1>CGI C Example #3</h1>\n");
place = getval("place");
if(place == NULL)
{
printf("<p>Data error</body></html>\n");
exit(0);
} /* now to connect to the database */
if(err)
{
printf("
Error connecting to database</body></html>\n");
exit(0);
} /* now construct SQL query in 'sqlbuff' */
/***************************************************************/
sprintf(sqlbuff,"SELECT * FROM gazetteer WHERE feature = \'%s\'",place);
if(mysql_real_query(&dbase,sqlbuff,strlen(sqlbuff)))
{
printf("<p>SQL error</body></html>\n");
exit(1);
}
/***************************************************************/
result = mysql_store_result(&dbase);
nrows = mysql_num_rows(result);
if(nrows == 0)
{
printf("No entries for %s</body></html>\n",place);
}
else
{
int i;
MYSQL_ROW row;
printf("<table border=2>\n");
for(i=0;i<nrows;i++)
{
int j;
row = mysql_fetch_row(result);
printf("<tr>");
for(j=2;j<6;j++) printf("<td>%s",row[j]);
printf("\n");
}
printf("</table></body></html>\n");
}
}
----阿菜