ai didi

php - 在 php 中连接到 mysql 时,query_id 没有返回任何内容

转载 作者:行者123 更新时间:2023-11-30 23:27:14 24 4
gpt4 key购买 nike

我的查询是:

$sqlCommand="select `ID` from `freecomputermarket`.`members` where `UserName`='$this->_userName';";

我使用 XAMPP 作为 apache 服务器,我正在端口 (89) 上工作

这个类负责数据库连接:

<?php
class MySql
{
private $_link_Id,$_query_Id,$_serverName,$_userName,$_password,$_dbName,$_rowNum;

public function __construct()
{
$this->_serverName="localhost";
$this->_userName="root";
$this->_password="";
$this->_dbName="freecomputermarket";
}
public function connect()
{
$this->_link_Id=mysql_connect($this->_serverName,$this->_userName,$this->_password);
if(!$this->_link_Id)
{
exit("The Connect is Failed");
}
$db_select=mysql_select_db($this->_dbName,$this->_link_Id);
if(!$db_select)
{
exit("Can't Select DataBase");
}
}
public function query($sqlcommand)
{
$sqlcommand= addslashes($sqlcommand);
//echo $sqlcommand;
$this->_query_Id=mysql_query($sqlcommand,$this->_link_Id);
exit($this->_query_Id);//print it to check if it is available.
if(!$this->_query_Id)
exit("Query failed");
$this->_rowNum=mysql_affected_rows();
}
public function getRow()
{
if($this->_rowNum)
{
return mysql_fetch_assoc($this->_query_Id);
}
}
public function getAllRows()
{
$arr=array();
$count=0;
while($count<$this->_rowNum)
{
array_push($arr,$this->GetRow());
$count++;
}
return $arr;
}
public function getAffectedRowsNumber()
{
return $this->_rowNum;
}
}
?>

此代码用于连接到 mysql 数据库管理系统并执行查询。打印 $_link_Id 时,它有一个值。打印$_query_Id的时候什么都没有?

最佳答案

问题来了

$sqlcommand= addslashes($sqlcommand);

不要使用加斜线。

这样使用

//$sqlcommand= addslashes($sqlcommand);
$this->_query_Id=mysql_query($sqlcommand,$this->_link_Id);

关于php - 在 php 中连接到 mysql 时,query_id 没有返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12621556/

24 4 0
文章推荐: php - 如何在 Mysql 中实现搜索查询
文章推荐: c# - 即使 Json 无效,如何解析第一个属性?
文章推荐: python - 使用格式模式将字符串反序列化为值
文章推荐: c# - BitmapImage:如何在返回图像之前等待 BitmapImage 初始化? (C#.NET)
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com