class Mysql{
var $error; //错误信息
var $link; //数据库连接
var $temp;
/*连接服务器*/
function my_connect($host,$dbuser,$dbpass,$dbname){
$this->link=mysql_connect($host,$dbuser,$dbpass);
$this->my_select_db($dbname);
}
/*选择数据库*/
function my_select_db($dbname){
$temp1 = mysql_select_db($dbname,$this->link);
if($temp1 == NULL){
echo mysql_error($this->link);
exit;
}else{
return true;
}
}
/*执行sql语句*/
function my_query($query){
$this->temp = mysql_query($query,$this->link);
if($temp == NULL){
echo mysql_error($this->link);
exit;
}else{
return $this->temp;
}
}
function my_num(){
return mysql_num_rows($this->temp);
}
/*查找用户信息*/
function select($name){
if($this->my_num() > 0){
for ($i=0;$i<$this->my_num();$i++){
return mysql_result($this->temp,$i,$name);
return "<br>";
}
}
}
}$test = new Mysql();
$host = "localhost";
$user = "root";
$passwd = "123456";
$database = "test";
$test->my_connect($host,$user,$passwd,$database);
$quert_str = "select * from test_tables";
$test->my_query($quert_str);
echo $test->select("name");上面的代码老是有错误但不知道什么原因 my_query()方法老是不能使用,请高手看下怎么回事
小弟就是想当$quert_str的语句不一样时,my_query()方法能及时执行$quert_str语句
解决方案 »
- 关于php连接数据库
- ecshop新加模板当前位置和分页的链接地址不能关联问题
- php中執行system('cls');的奇怪問題
- 100分请教像126、163等邮箱的通讯录克隆是如何实现的,请各位给个思路。多谢
- 没分了。不好意思。问个动态赋值的问题。在线等啊,急~
- 北美的公司高薪聘请PHP/MYSQL资深程序员多名
- 请指教
- 我已经集中进行结贴了(随时结很麻烦)。但有部分是没有得到回复或没有得到正确回复的。请斑竹帮忙结贴,将分还给我。怎么不见任何消息?
- 请教: 一个sql语句的写法
- 如何在win2k安装php+apache+mysql+phpmyadmin?
- php如何传递map类型给JAVA webservice,求高手看下为什么JAVA服务端接收不到参数
- 求助:对PHP上传的文件,立即操作失败的问题!
$this->temp = mysql_query($query,$this->link);
}