pike连接Mysql的问题,请高手赐教
用pike写了个小程序(tt.pike)连接mysql.
如下:
int main()
{
Mysql.mysql("localhost","database_test","root","123123");
Mysql.mysql()->big_query("select * from table_test limit 1");
return 1;
}
执行pike tt.pike报错如下:
Mysql.mysql(): Couldn't reconnect to SQL-server
Access denied for user: 'root@localhost' (Using password: NO)
Mysql.mysql:
Mysql.mysql()->_sprintf("Mysql.mysql(): Couldn't reconnect to SQL-servernAccess denied for user: 'root@localhost' (Using pass
word: NO)n")
/usr/local/pike/7.4.28/lib/master.pike:2607: master()->describe_function(Mysql.mysql()->create)
/usr/local/pike/7.4.28/lib/master.pike:2717:
master()->describe_backtrace(({backtrace_frame(/usr/local/pike/7.4.28/lib/master.pike:1957, _main(), Args: 2),backtrace_frame(
/home/test/xw/tt.pike:11, main(), No args),backtrace_frame(Unknown file, create(), No args)}),132)
/usr/local/pike/7.4.28/lib/master.pike:727:
master()->handle_error(({"Mysql.mysql(): Couldn't reconnect to SQL-servernAccess denied for user: 'root@localhost' (Using pas
sword: NO)n",,,0}))
Mysql.mysql(): Couldn't reconnect to SQL-server
Access denied for user: 'root@localhost' (Using password: NO)
Mysql.mysql: Mysql.mysql()->create()
tt.pike:11: tt()->main()
不知道为什么老连不上,请赐教.
pike文档: http://pike.ida.liu.se/generated ... l/mysql/create.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
int main()
{
object a = Mysql.mysql("localhost","testdb","root","123123");
object b = Mysql.mysql_result;
b = a->big_query("select * from test");
array result = b->fetch_row();
write("result--"+ result[1] +"n");
return 1;
}
说明:
1、构造一个Mysql对象a,并连接数据库。
2、构造一个结果集对象b。
3、执行SQL操作,结果放到对象b中。
4、从游标中取出一行。
5、取出这一行的第二列数据。
注意分清面向对象的概念。
如果直接这么写:
int main()
{
Mysql.mysql("localhost","testdb","root","123123");
Mysql.mysql->big_query("select * from test");
return 1;
}
这样会报错:Mysql.mysql(): Couldn't reconnect to SQL-server,重连接错误。相当于两次构造Mysql对象。