在PHP中从面向对象更改为过程

时间:2016-04-19 09:28:54

标签: php

我正在创建一个连接到数据库的if(open LOGFILE, 'tail /some/log/file |' and open TAIL, '>/tmp/logtail') { print LOGFILE "$_\n" while <TAIL>; close TAIL and close LOGFILE } 页面,它确实很好地连接到了它,但是我想将它从面向对象的编程改为过程式编程。我想要更改的代码中的行是PHP$result = $conn->query("select * from user where usernam' ".$username."' ");。我在网上做过一些研究,我发现是here

1 个答案:

答案 0 :(得分:2)

从面向对象编程转向程序编程就像从21世纪走向石器时代世界。我的建议是,保持面向对象的模式。

但话说回来,如果你真的想要程序化方式,那就改变

$result = $conn->query("select * from user where usernam = '".$username."'");

$result = mysqli_query($conn, "select * from user where usernam = '".$username."'");

并更改

if($result->num_rows>0)

if(mysqli_num_rows($result) > 0)