Page 1 of 1

Some questions on php

Posted: Thu Jul 21, 2011 3:10 am
by jtman
Hi, I'm new in php, came across piece of code which I leaves me scratching my head:

Code: Select all

$dbi->query($sql_line)
A number of questions here:
1) What is the "->" operator? I can't find any reference to it except that it is used in Perl.
2) Is this statement querying the database? Why not use the standard php statements for querying the database?

My apologizes if my questions sounds basic. Thanks in advance for the help!

Re: Some questions on php

Posted: Thu Jul 21, 2011 8:06 am
by Corvin
1) It's the arrow operator. You use it to access methods and properties of a class.
2) Yes, it seems that a database class is used to simplify database interaction.

:arrow: http://www.php.net/manual/en/language.oop5.php

Re: Some questions on php

Posted: Sat Jul 23, 2011 5:44 am
by jtman
Thank you for your help!
Encountered another though,

Code: Select all

<?php
$myfiles=array("test.sql");

foreach ($myfiles as $file) {
	$sql=file_get_contents($file);
		
	$sql_line_m="C";
	print(strcmp($sql,$sql_line_m));
	print("\n".strcmp($sql_line_m,$sql));
	
}
?>
The contents of the test.sql file is just "C".
But the output is:
1
-1

Shouldn't it be 0, equal?

Re: Some questions on php

Posted: Sat Jul 23, 2011 11:18 am
by Corvin
The contents of the test.sql file is just "C".
Maybe it's "C ".

Re: Some questions on php

Posted: Mon Jul 25, 2011 1:30 pm
by Benjamin
:arrow: Moved to PHP - Code