我的家伙,我在那里用的小白问题,再次是 我之前1页进行单独从我的数据库选择数据和它的作品,这是代码:从数据库与phpoo选择
<?php
$ligacao = mysql_connect("localhost", "root", "") or die
("problemas na ligaçao ao MySQL");
mysql_select_db("test", $ligacao);
$sql = "select nome, telefone from teste";
$resultado = mysql_query($sql, $ligacao);
while ($registo = mysql_fetch_row($resultado)){
print ("$registo[0] --- $registo[1] <br>");
}
mysql_close();
?>
现在我tryed把在类和函数运行安全,我的确在类文件夹是这样的 :
<?php
class vari{
/* variables needed */
protected $hostname;
protected $username;
protected $dbpass;
protected $db;
protected $sql;
protected $ligacao;
protected $resultado;
protected $registo;
public function liga() {
$db = new vari;
$db->hostname = 'localhost';
$db->username = 'root';
$db->dbpass = '';
$db->db = 'mysql_select_db("test", $this->liga)';
$db->sql = '"select nome, telefone from teste";';
$db->ligacao = 'mysql_connect($this->hostname, $this->username, $this->dbpass)';
$db->resultado = 'mysql_query($this->sql, $this->ligacao)';
$db->registo = 'mysql_fetch_row($this->resultado)';
mysql_select_db($db->db, $db->ligacao);
while ($db->registo = 1){
print ("$db->registo[0] --- $db->registo[1] <br>");
}
mysql_close();
}
}
,并在指数端起:
<?php
include 'class/classes.php';
$data= new vari;
$data->liga();
?>
毕竟努力工作,我去看看hapenned和我有一个无穷远循环是这样的:
PHP Error Message
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/test1/class/classes.php on line 24
Free Web Hosting
1[0] --- 1[1]
1[0] --- 1[1]
1[0] --- 1[1]
1[0] --- 1[1]
1[0] --- 1[1]
1[0] --- 1[1]
什么是错的代码?我明白了功能的含义和上课时间,即时学习,但这里的问题与我想到的变量有关,你们能帮我解决这个问题吗?对不起,很长的帖子... ,并立即感谢awesome;) kjonh2
为什么不使用[PDO](http://fr2.php.net/manual/en/book.pdo.php)? .. – Bobot
你为什么试图使用mysql_扩展? – sectus
个人而言,我不明白为什么你花这么多时间,使用'mysql_' –