-1

I have been doing my Homework regarding mongodb and PHP and honestly, I'm fairly new at this and this is my first post at SO.

What does"." operator do in PHP?

For example

  $cmd = "SELECT m_time,m_latency,m_length FROM pkt_tbl WHERE m_in_port=". $in_port

What does "." in .$in_port mean? How can I convert the entire syntax to mongodb?

This is my try:

$db->pkt_tbl->find(array("m_in_port=".$inport,array("m_time"=>1,"m_latency"=>1,"m_length"=>1));

Please correct my syntax and enlighten me regarding "." operator, I badly want to learn and I'm a newbie at PHP and mongodb.

iron man
  • 41
  • 8
  • it's just the strings concatenation operator – Ziumin Jul 11 '13 at 19:47
  • wow. it's really a warm welcome isn't it. I have done as much homework as I can and I get a "-1"rating on my post. Well done guys! – iron man Jul 11 '13 at 19:48
  • @Ziumin: Yes, Indeed.I thought so but I just wanted to see if I can directly use that in Mongodb syntax just like how I did it or do i have do something else. Could you please look at my syntax and judge If I did right? – iron man Jul 11 '13 at 19:49
  • If you do a google search for 'php period', you get http://stackoverflow.com/questions/6159172/why-are-there-periods-in-php – aynber Jul 11 '13 at 19:49

2 Answers2

0

That is incorrect PHP. Try:

$db->pkt_tbl->find(
    array("m_in_port"=>$inport),
    array("m_time"=>1,"m_latency"=>1,"m_length"=>1)
);
Sammaye
  • 40,888
  • 7
  • 90
  • 139
  • Thank you for your response, It's appreciated. However, What does it mean when we say "m_time" => 1 (When it's not mentioned anything in the original syntax, why do we equate it to one)? I'm sorry, I'm a total newbie and I am just trying to learn mongodb. – iron man Jul 11 '13 at 19:51
  • @ironman Going through the tutorial will help here: http://www.php.net/manual/en/mongo.tutorial.php , however, when you state 1 or 0 in the list of fields in the projection (the second array) 1 states to include the field while 0 states not to. – Sammaye Jul 11 '13 at 19:53
  • wow, thank you so much! It's been a great help guys! – iron man Jul 11 '13 at 19:55
  • Thanks for your responses, I have learn't a lot from this thread(That's the purpose of this forum and I'm lovin it!) Another query that I have tried, Critique Please. Sql Statement: `$cmd = "SELECT m_out_port FROM pkt_tbl WHERE m_time>=" . $selPointX . " ORDER BY m_time LIMIT 1";` Mongod Statement: `$find_query = $db->pkt_tbl->find( array('m_time'=>$selPointX), array('m_out_port'=>1), sort(array('m_time'=>1)->limit(1));` Please validate. – iron man Jul 11 '13 at 23:39
  • @ironman You want to use http://docs.mongodb.org/manual/reference/operator/gte/ on `m_time` – Sammaye Jul 12 '13 at 07:09
0

In PHP, . is the concatenation operator. It tells the interpreter to stick strings or variables together end-to-end. For example, "hello " . "world" is equivalent to "hello world". In the case of your example, if $in_port=10, then your line of code would be equivalent to "SELECT m_time,m_latency,m_length FROM pkt_tbl WHERE m_in_port=10";

IanPudney
  • 5,531
  • 1
  • 20
  • 37
  • wow, couldn't have been any better. Thank you. What does it mean when we say "m_time" => 1 (When it's not mentioned anything in the original syntax, why do we equate it to one? – iron man Jul 11 '13 at 19:52