PHP 对象到字符串
我花了 2 个小时在 Stack Overflow 上搜索了有关这个问题的其他几篇文章,它们似乎比我需要的更复杂。我尝试执行 __toString 函数,但我认为我做得不正确。
我正在尝试获取 $personid 的 sql 语句并将其转换为字符串,以便我可以在其他 sql 方法中使用它。
$personid = $this->db->query('SELECT person_id FROM person');
$fullname = $this->db->query("SELECT person_fname, person_lname FROM person
WHERE person_id = '".$personid."';");
$sport = $this->db->query("SELECT sport_name FROM person_sport_rel A1
INNER JOIN sport A2 ON A1.sport_id = A2.sport_id
WHERE person_Id = '".$personid."';");
正如其他帖子有问题一样..我收到的错误是
Object of class CI_DB_mysql_result could not be converted to string
我尝试在 PHP 网站上推荐的 CI_DB_mysql_result 类中添加构造函数和 __toString 但无济于事
I spent 2 hours searching through the other few posts at Stack Overflow concerning this issue and they seemed more complicated than what I needed. I attempted doing the __toString function but I don't think I did it correctly.
I am trying to take the sql statement for $personid and convert it to a string so I can use it in the other sql methods.
$personid = $this->db->query('SELECT person_id FROM person');
$fullname = $this->db->query("SELECT person_fname, person_lname FROM person
WHERE person_id = '".$personid."';");
$sport = $this->db->query("SELECT sport_name FROM person_sport_rel A1
INNER JOIN sport A2 ON A1.sport_id = A2.sport_id
WHERE person_Id = '".$personid."';");
Just as the other posts had the problem.. the error I receive is
Object of class CI_DB_mysql_result could not be converted to string
I tried adding the constructor and the __toString in the CI_DB_mysql_result class that was recommended on the PHP site but to no avail
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来好像您正在使用 Codeigniter,要获取查询结果,请检查此网站: http://www.codeignitor.com/user_guide/database/results.html
从该页面:
It looks as though you are using Codeigniter, to fetch the results of a query, check this website: http://www.codeignitor.com/user_guide/database/results.html
From that page:
当您运行此查询时,您可能会返回一堆 id:
因此,当您想在新查询中重复使用它时,这可能更有趣:
CI 用户指南在这方面提供了很好的帮助:http://www.codeignitor.com/user_guide/database/
You are probably returning a bunch of id's when you're running this query:
so when you want to re-use it in new queries this is probably more interesting:
The CI userguide is a good help in this : http://www.codeignitor.com/user_guide/database/