在 oop php 中,我创建了构造函数 mysql 连接(我知道它会被弃用,您建议使用 PDO 等等),但我遇到了问题。连接已建立,一切正常。但是插入不能做不知道为什么,代码一直运行到最后。似乎该对象没有连接,但它不可能。我使用 PHP 5.4.3。代码如下:
Table (Coach):
Coach_id INT (AutoIncrement)
Coach_name char(30)
Coach_nationality char(30)
class League
{
public $con;
public function MySQLCon()
{
$this->con = mysql_connect("localhost","root","") or mysql_error($this->con);
mysql_select_db("basket",$this->con) or mysql_error($this->con);
return $this->con;
}
public $coach,$coachNationality;
public function NewCoach($coach,$coachNationality)
{
$this->coach = $coach;
$this->coachNationality = $coachNationality;
$Query = "insert into Coach_name (Coach_name,Coach_nationality) VALUES ('".$this->coach."','".$this->coachNationality."')";
//this query doesn't do anything but prints yes
mysql_query($Query,$this->con) or mysql_error($this->con);
echo "yes";
}
}
//no data about mike Brown in database, database engine InnoDB
$LG = new League;
$LG->MySQLCon();
$LG->NewCoach("Mike Brown","USA");