Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

mysql/php


Demons Halo's Avatar
Member
0 0

I know I'm going to get flamed for this, but what the heck I like spyware anyway ^^

I've just started learning mysql & php and as a first impression I might say that things seems rather easy to understand, yet when I try to connect to my MySQL server using php, nothing happens O.o

I'm using one.com as host

<?php
mysql_connect("dbadmin.one.com", "username goes here", "password goes here") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("database goes here") or die(mysql_error());
echo "Connected to Database";
?>

what the heck am I doing wrong? x_x

edit: dbadmin.one.com –> is the MyPhpAdmin address, there is no other address to connect to, so… where do I go from here? :P


Demons Halo's Avatar
Member
0 0

MoshBat wrote: For starters, "localhost".

come on.. how stupid am I :'( ofc it's localhost since the freaking file is already on the host server -__________-

anyway keep tune, more stupid questions will show up eventually :P

thnx pikabat (L)


Demons Halo's Avatar
Member
0 0

MoshBat wrote: No. No. Rather than "blah.one.com", "localhost". And let me take another look at that script.

ah I got that, stupid noob mistake by me not to put localhost from the start

<?php
mysql_connect("localhost", "username", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("demonshalo_com") or die(mysql_error());
echo "Connected to Database";

$query = "SELECT * FROM test"
$result = mysql_query($query) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['id']. " - ". $row['testare'];

?>

in MyPhpAdmin I've created a table called test with 2 fields (id, testare). So far I can connect and select a database, but I can't seem to show the content of the table. :/

edit: I'm probably going to get pawned for posting the code here…


Demons Halo's Avatar
Member
0 0

awesome, I got it working as well but I hate how you guys make the code seem so clean and professional -_-

$row = mysql_fetch_array($result) or die(mysql_error());

the little "or die(mysql_error())" messed everything up, once I removed it everything worked.

hmm a while loop to print out all the rows =O nice! thnx =D

edit: I'm not here to copy/paste… I'm hear to learn from you holy one! *_'


Demons Halo's Avatar
Member
0 0

as long as I understand the concept I don't care if you color or use black text & black background -_- what idea? O.o

haha that's some "sexy" code right there… NOT

"EDIT#2: Whilst we're here, and I'm bored, any more PHP issues?"

they will eventually pop-up :P If you've got some advice for a beginner don't hesitate to post them xD


Demons Halo's Avatar
Member
0 0

MoshBat wrote: [quote]Demons Halo wrote: If you've got some advice for a beginner don't hesitate to post them xD

Don't be scared to post your problems. I was nice, was I not? Also, you can contact me in any way you wish, (except perhaps sending your problem via traditional mail, written in your own faeces) and I'll be more than happy to help you.[/quote]

you're always nice =D and just for the record: I like getting flamed XD haha thnx a lot, I really appreciate it.

I have a security question though. A lot of the exploits/hacks done on the web are SQL based, how do I avoid those security issues?


Demons Halo's Avatar
Member
0 0

I'll check that out asap!

here is my first project using php/mysql: I'm going to build a photo gallery using a table with the fields: id, picture, comment and date.

correct me if I'm wrong but this is how a table should look like:

--------------------------------------------------
| id   |  picture         | comment        |    date      |
--------------------------------------------------
| 1   | images/lal.jpg  | rofl lmao wtf?  | CURDATE() |
---------------------------------------------------

now using php I should do something like:

$result = mysql_query("SELECT * FROM gallery");

while($row = mysql_fetch_array($result)){
	$picture= $row['picture'];
	$comment = $row['comment'];
	$date = $row['date'];
	print "<img src=$picture>-  comment: $comment  -  date: $date <br />";
}

This doesn't work, so I need to know how to load an image to the browser using php. I've found a lot using google, but unfortunately the shortest code I could understand was half a page long -_- is there any easy way to do this?

Edit: I got it working. Minor problem with the quote marks xD


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

MoshBat wrote: [quote]Demons Halo wrote: I'll check that out asap!

here is my first project using php/mysql: I'm going to build a photo gallery using a table with the fields: id, picture, comment and date.

correct me if I'm wrong but this is how a table should look like:

--------------------------------------------------
| id   |  picture         | comment        |    date      |
--------------------------------------------------
| 1   | images/lal.jpg  | rofl lmao wtf?  | CURDATE() |
---------------------------------------------------

now using php I should do something like:

$result = mysql_query("SELECT * FROM gallery");

while($row = mysql_fetch_array($result)){
	$picture= $row['picture'];
	$comment = $row['comment'];
	$date = $row['date'];
	print "<img src=$picture>-  comment: $comment  -  date: $date <br />";
}

Edit: I got it working. Minor problem with the quote marks xD

For the benefit of those who may suffer similar problems:

$result = mysql_query("SELECT * FROM gallery ORDER BY id ASC");

while($row = mysql_fetch_array($result)){
	$picture= $row['picture'];
	$comment = $row['comment'];
	$date = $row['date'];
	print "<img src='$picture' /> -  comment: $comment  -  date: $date<br />";
}

Note the added apostrophes ('), and the / in the img tag :) If memory serves, not closing the img tag can cause fuckups in IE6.[/quote]

Self-closing tags are needed for XHTML, however they aren't for standard HTML, so it won't cause fuckups in IE6.

Also, use "echo" instead of "print", it's faster.


spyware's Avatar
Banned
0 0

MoshBat wrote: At his level, mere milliseconds don't really matter.

It doesn't matter whether it matters now. It could matter in the future.

Suboptimal programming is stupid.


Demons Halo's Avatar
Member
0 0

emm print returns boolean as well right? while echo just "writes" stuff :P

edit: another question: what alternatives are there for loading a page inside of another page? php include / Iframe / jQuery are the ones I know of, any other methods?

using php includes would make the entire site reload, which I actually don't mind, but I'm just wondering what the best method is :P


spyware's Avatar
Banned
0 0

Demons Halo wrote: I'm just wondering what the best method is :P

Depends what you want to use it for/how you want to use it.


Demons Halo's Avatar
Member
0 0

spyware wrote: [quote]Demons Halo wrote: I'm just wondering what the best method is :P

Depends what you want to use it for/how you want to use it.[/quote]

currently i use the following in index.php:

<body>
	<div id="Main" align="center">
		<div id="top">
			<?php include 'top.php'; ?>
		</div>
		<div id="Body" align="left">
			<iframe align="left" id="Iframe" name="Iframe" src="home.php" width="100%" height="100%" style="background-color:transparent; border:none;" scrolling="yes">
			</iframe>
		</div>
	</div>
</body>

I want to get rid of the Iframe by using another method like php include. The idea is when a user clicks on a button (inside top.php), the "body div" in the index.php should change and show the content of a new page depending on what button the user clicks.


ghost's Avatar
0 0
<?php
$page = $_GET['page'];
?>
<body>
  <div id="Main" align="center">
     <div id="top">
       <?php include 'top.php'; ?>
     </div>
     <div id="Body" align="left">
      <?php include $page; ?>
     </div>
  </div>
</body>

The links within top.php should be like

<a href="index.php?page=lol.php">lol</a>

Obviously, you wil ned security measures :P


ghost's Avatar
0 0

pm me if you need anymore help


ghost's Avatar
0 0

quick question Demons Halo, is one.com a good host…i was going to go for it but i was unsure. it seems pretty good but i thought there would be a catch somewhere. cheers


Demons Halo's Avatar
Member
0 0

christian879 wrote:

<?php
$page = $_GET['page'];
?>
<body>
  <div id="Main" align="center">
     <div id="top">
       <?php include 'top.php'; ?>
     </div>
     <div id="Body" align="left">
      <?php include $page; ?>
     </div>
  </div>
</body>

The links within top.php should be like

<a href="index.php?page=lol.php">lol</a>

Obviously, you wil ned security measures :P

ahaaaaaa so that's how the ?page… works, this is indeed handy. What security measures do you have in mind? I'm still a noob remember xD I can't work with complicated 14 page script stuff (yet).

quick question Demons Halo, is one.com a good host…i was going to go for it but i was unsure. it seems pretty good but i thought there would be a catch somewhere. cheers

Yes they are.

24/7 support cheap registration 100% secure when it comes to credit card number etc. Easy access MySQL DB + latest version of PHP 3000MB for 1.25€ / month –> lol? Lots of features for admins using IE Google Adwords coupon

No CGI support.

Note: pretty decent connection.

Total: 9/10 so go for it ;)


ranma's Avatar
Member
0 0

And here I thought DH was some quite experienced guy :p

I would suggest GoDaddy hosting. Their customer service is AMAZING and they have tons and tons of features.


ghost's Avatar
0 0

ranma wrote: And here I thought DH was some quite experienced guy You best be jokin, nigga! :P

Demons Halo wrote: ahaaaaaa so that's how the ?page… works Please man, for the love of chocolate, look into some basic http before you delve into PHP. You don't hate chocolate… do you? :o


ranma's Avatar
Member
0 0

But seriously, some of those question could have been easily answered by looking at w3schools's php/mysql tutorials.


Demons Halo's Avatar
Member
0 0

COM wrote: [quote]ranma wrote: And here I thought DH was some quite experienced guy You best be jokin, nigga! :P

Demons Halo wrote: ahaaaaaa so that's how the ?page… works Please man, for the love of chocolate, look into some basic http before you delve into PHP. You don't hate chocolate… do you? :o[/quote]

HEY HEY HEY!!!! hey I'm a noob I admit that much :P and thnx for believing in my hidden power ranma! (L)

haha I love chocolate, I even married it once! Just to be 100% clear… I HATE BUILDING WEBB BASED PROGRAMMING. I joined this community so that I could learn a bit about computer languages (and thnx to ynouri7 I started with python). yesterday I got bored so I thought that maybe it's time to start with something else like PHP/MySQL :P and so fast everything seems easy and fun =D

and yes ranma W3school is great, although I'm googling most of the questions I've got. Having stuff explained on the spot is so much better than reading through 16 pages just so that you notice the FREAKING ; you need to put at the end of each line -_-


ranma's Avatar
Member
0 0

Oh yeah, most programming errors are usually just forgetting a ; or a ' or mixing up a 1 with a l. You can't really get bored with a programming language unless you just learn the syntax and then nothing else. You need a nice project. For example, make a text-based rpg in python. Make it so it loads a map, has menus, new character, you can switch items, fight creeps, get quests, etc. I've been working on one in C++ for a while (well, last time was around 9 months ago :p)


ghost's Avatar
0 0

Demons Halo wrote: haha I love chocolate, I even married it once!

Damn it, I suspected that bitch was cheating on me, but with you of all people?

Just to be 100% clear… I HATE BUILDING WEBB BASED PROGRAMMING.

w00t? You just wasted one hundred poor little percentages, have you no shame?

I joined this community so that I could learn a bit about computer languages (and thnx to ynouri7 I started with python).

Oi! Respect the man who teaches you and get his name right, you even did an edit and left it the same.

yesterday I got bored so I thought that maybe it's time to start with something else like PHP/MySQL :P and so fast everything seems easy and fun =D

So, now for my actual point from previously which from what I managed to understand from what you wrote, you had some issue with or something. If you dislike "BUILDING WEBB BASED PROGRAMMING" then know that http is just a protocol. (http <– see the p?) My reason for saying that it would be best to learn some basic http is that you will get a general understanding of how a request for a page looks like and how it's expected to be processed. Which will then make it easier to actually deal with things over the net if you ever have to program something that deals directly with these things. Furthermore you'll recognize the different parts of http when you learn PHP and remember what the hell they are and it'll be easier to understand what exactly PHP is expecting to do with it and how it'll work. The basics in http isn't very much even, I'm just saying do yourself a favour, it's good to know. Now if you'll excuse me I'm going to go try and talk to my chocolate about where our relationship is currently, and we were going to have children next year too :(

P.S. If you still don't get it I can shout at you some in Swedish too.


ranma's Avatar
Member
0 0

I've never really looked up http to understand how its basics work, as COM said. I started PHP in 6th grade and I was fine. Come on. You can't get it?


Demons Halo's Avatar
Member
0 0

COM wrote: Damn it, I suspected that bitch was cheating on me, but with you of all people? don't understimate me…

Oi! Respect the man who teaches you and get his name right, you even did an edit and left it the same. dude… since when do I spell shit right? read through my previous posts and you'll see.

So, now for my actual point from previously which from what I managed to understand from what you wrote, you had some issue with or something. If you dislike "BUILDING WEBB BASED PROGRAMMING" then know that http is just a protocol. (http <– see the p?) My reason for saying that it would be best to learn some basic http is that you will get a general understanding of how a request for a page looks like and how it's expected to be processed. Which will then make it easier to actually deal with things over the net if you ever have to program something that deals directly with these things. Furthermore you'll recognize the different parts of http when you learn PHP and remember what the hell they are and it'll be easier to understand what exactly PHP is expecting to do with it and how it'll work. The basics in http isn't very much even, I'm just saying do yourself a favour, it's good to know. Now if you'll excuse me I'm going to go try and talk to my chocolate about where our relationship is currently, and we were going to have children next year too :(

P.S. If you still don't get it I can shout at you some in Swedish too.

lol XD sure I'll check it out right now. And hey, I know what http stands for x_X

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol nothing really new there. I read about that shit while doing programming challenges!


Demons Halo's Avatar
Member
0 0

ranma wrote: Oh yeah, most programming errors are usually just forgetting a ; or a ' or mixing up a 1 with a l. You can't really get bored with a programming language unless you just learn the syntax and then nothing else. You need a nice project. For example, make a text-based rpg in python. Make it so it loads a map, has menus, new character, you can switch items, fight creeps, get quests, etc. I've been working on one in C++ for a while (well, last time was around 9 months ago :p)

I'm working ona game right now using python/pygame. It's fun but I need a break from all that shit :P


Demons Halo's Avatar
Member
0 0

MoshBat wrote: Rather than include(), use require(). Include only gives a warning if a file is not found, but require halts the program.

SIR YES SIR! I'm using include atm, I'll replace it asap!

next question: I've created several tables, one for each sub-site (downloads, projects, gallery, etc.). In every site (downloads.php, peojects.php, etc.) I use the mysql_connect function to connect to the mysql server. Is this the right way of doing what I'm doing, or is there a better way? like connecting to the mysql and have the connection established all the time?


ghost's Avatar
0 0

ranma wrote: Oh yeah, most programming errors are usually just forgetting a ; or a ' or mixing up a 1 with a l.

It is in those times that it's good to have a smart compiler that says "hey, you forgot a ';' at the end of line 69." or "possible misspelling: 'wanka' instead of 'wanker' at line 96.".


Demons Halo's Avatar
Member
0 0

c4p_sl0ck wrote: [quote]ranma wrote: Oh yeah, most programming errors are usually just forgetting a ; or a ' or mixing up a 1 with a l.

It is in those times that it's good to have a smart compiler that says "hey, you forgot a ';' at the end of line 69." or "possible misspelling: 'wanka' instead of 'wanker' at line 96.".[/quote]

any recommendations? I want a compiler that can help me with python/php & (C/C++ soon enough :P)


ghost's Avatar
0 0

Well, for PHP I don't know any. I was just pointing out that a downside of not compiling is that you can't have a smart compiler. Use an editor which color-codes and indents your code automatically and it'll be easy to spot syntax errors.


Demons Halo's Avatar
Member
0 0

c4p_sl0ck wrote: Well, for PHP I don't know any. I was just pointing out that a downside of not compiling is that you can't have a smart compiler. Use an editor which color-codes and indents your code automatically and it'll be easy to spot syntax errors.

and that's what I meant by "compiler" :P (Editor), and yes I know the difference -_-

ah Notepad++ was the name of the editor, thnx pikabat!


ghost's Avatar
0 0

Demons Halo wrote: and that's what I meant by "compiler" :P (Editor), and yes I know the difference -_-

(thumbs up) I think that the ConTEXT editor is good. http://www.contexteditor.org/


Demons Halo's Avatar
Member
0 0

thnx sweety =D I'll check that one out as well =D

Now I've got a question… How about security? especially when it comes to avoiding sql injections, any tips?


ghost's Avatar
0 0

pimpim wrote: [quote]Demons Halo wrote: thnx sweety =D I'll check that one out as well =D

Now I've got a question… How about security? especially when it comes to avoiding sql injections, any tips?

Use addslashes() or (preferably) mysql_real_escape_string() to avoid SQL-Injections.

http://fi.php.net/manual/en/function.mysql-real-escape-string.php http://fi.php.net/manual/en/function.addslashes.php

[/quote]

Yeah, definitly mysql_real_escape_string, it's the shizzle :ninja:


Demons Halo's Avatar
Member
0 0

ooookay =D

here is what I'm doing:

First I'm passing a lot of values in between pages with

&lt;a href=&#39;music-viewer.php?genre=bootleg&#39;&gt;whatever&lt;/a&gt;

after that I grab the values & edit them in the music-viewer.php using

$genre = $_GET[&#39;genre&#39;];
$genre = mysql_real_escape_string($genre);

after that I connect using the following query

$result =  mysql_query(&quot;SELECT * FROM music WHERE ggenre=&#39;$genre&#39; ORDER BY date&quot;);

The code above does what it's suppose to do, although is it enough to prevent sql injections? I've been reading about real_escape_string and how it works (the escape backslash thingy). The method seems awesome, yet there are few people out there that keep yapping about needing more than that o prevent sql injections.

Edit: http://www.rohitab.com/discuss/lofiversion/index.php/t9626.html This must be basics for some of you, yet I'm a bit concerned. using the '?xxx=yyy' extension to pass values in between pages seems a little risky. I'm using that sort of extension a lot atm –> passing values between pages –> values gets inserted in mysql_query statement.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

MoshBat wrote: [quote]Demons Halo wrote: ooookay =D

here is what I'm doing:

First I'm passing a lot of values in between pages with

&lt;a href=&#39;music-viewer.php?genre=bootleg&#39;&gt;whatever&lt;/a&gt;

after that I grab the values & edit them in the music-viewer.php using

$genre = $_GET[&#39;genre&#39;];
$genre = mysql_real_escape_string($genre);

after that I connect using the following query

$result =  mysql_query(&quot;SELECT * FROM music WHERE ggenre=&#39;$genre&#39; ORDER BY date&quot;);

The code above does what it's suppose to do, although is it enough to prevent sql injections? I've been reading about real_escape_string and how it works (the escape backslash thingy). The method seems awesome, yet there are few people out there that keep yapping about needing more than that o prevent sql injections.

Edit: http://www.rohitab.com/discuss/lofiversion/index.php/t9626.html This must be basics for some of you, yet I'm a bit concerned. using the '?xxx=yyy' extension to pass values in between pages seems a little risky. I'm using that sort of extension a lot atm –> passing values between pages –> values gets inserted in mysql_query statement. It should do just fine. Also: $genre = mysql_real_escape_string($_GET['genre']);

Much simpler.[/quote]

Although you may get a "Notice" from PHP if the script is accessed directly, as $genre will create a null reference.

Try:

&lt;?php

if( isset( $_GET[&#39;genre&#39;] ) )
{
  $genre = mysql_real_escape_string( $_GET[&#39;genre&#39;] );
  
  /* rest of code here */

}
else
  header( &quot;Location: index.php&quot; );

?&gt;

SySTeM's Avatar
-=[TheOutlaw]=-
20 0

MoshBat wrote: The one thing I forgot. Though, to my defence, it was quite early in the morning.

EDIT: Actually, System, this one is easier, though essentially the same, it depends on if the else is needed:

if(!isset($_GET[&#39;genre&#39;])){
   header( &quot;Location: index.php&quot; );
}
//else may be needed, it depends on what file you&#39;re using this in
$genre = mysql_real_escape_string($_GET[&#39;genre&#39;])
?&gt;```

Yeah they both do the same thing practically. However, you don&#39;t need the braces on the if when it&#39;s just a one liner.

```markup
if( !isset( $_GET[&#39;genre&#39;] ) )
   header( &quot;Location: index.php&quot; );

Would do fine.

However the reason I chose to do it differently, is maybe there are multiple arguments, so it could check if genre exists, then do some code, then check if "subgenre" exists as well, in the same code block.

&lt;?php

if( isset( $_GET[&#39;genre&#39;] ) )
{
  $genre = mysql_real_escape_string( $_GET[&#39;genre&#39;] );

  if( !isset( $_GET[&#39;subgenre&#39;] ) )
  {
     /* list subgenres */
  }
  else
  {
     /* do something */
  }
}
else
  header( &quot;Location: index.php&quot; );

?&gt;

spyware's Avatar
Banned
0 0

Student vs. Master?

Give up already, Mosh :P


Demons Halo's Avatar
Member
0 0

@ mosh indeed, using $genre is unnecessary -_-

@ spy how about me pawning both of them with my super duper script?

$ggenre = mysql_real_escape_string($_GET[&#39;ggenre&#39;]);
$genre = mysql_real_escape_string($_GET[&#39;genre&#39;]);
				
if($ggenre != NULL){
	$result =  mysql_query(&quot;SELECT * FROM music WHERE ggenre=&#39;$ggenre&#39; ORDER BY date&quot;);
}
else{
	$result = mysql_query(&quot;SELECT * FROM music WHERE genre=&#39;$genre&#39; ORDER BY date&quot;);
}

Demons Halo's Avatar
Member
0 0

MoshBat wrote: [quote]Demons Halo wrote:

$ggenre = mysql_real_escape_string($_GET[&#39;ggenre&#39;]);
$genre = mysql_real_escape_string($_GET[&#39;genre&#39;]);
				
if($ggenre != NULL){
	$result =  mysql_query(&quot;SELECT * FROM music WHERE ggenre=&#39;$ggenre&#39; ORDER BY date&quot;);
}
else{
	$result = mysql_query(&quot;SELECT * FROM music WHERE genre=&#39;$genre&#39; ORDER BY date&quot;);
}
if($_GET[&#39;ggenre&#39;] != NULL)
   $genre = mysql_real_escape_string($_GET[&#39;ggenre&#39;]);
else
   $genre = mysql_real_escape_string($_GET[&#39;genre&#39;]);

$result = mysql_query(&quot;SELECT * FROM music WHERE genre = &#39;$genre&#39; ORDER BY date&quot;);
?&gt;```

[/quote]

same shit different colors =D 
Although I had an important question. I&#39;m using mysql_connect in every php file without closing the connection at the end of the file. 
Is this the right way or should I close the mysql connection after receiving the data?

This is how I&#39;m doing it right now...

file1 (home.php):
```markup
mysql_connect = (&quot;localhost&quot;, &quot;we&quot;, &quot;we&quot;);

CODE GOES HERE

file 2 (gallery.php):

mysql_connect = (&quot;localhost&quot;, &quot;we&quot;, &quot;we&quot;);

CODE GOES HERE

ghost's Avatar
0 0

system_meltdown wrote: Alternatively, create a your own MySQL class.

Or if you don't have time, knowledge or don't feel like it, you can use the MySQLi class instead of making your own.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

c4p_sl0ck wrote: [quote]system_meltdown wrote: Alternatively, create a your own MySQL class.

Or if you don't have time, knowledge or don't feel like it, you can use the MySQLi class instead of making your own.[/quote]

Yeah that's a good point, only reason I suggested creating your own is it will benefit with learning concepts of OOP.


p4plus2's Avatar
Member
0 0

system_meltdown wrote:

Yeah that's a good point, only reason I suggested creating your own is it will benefit with learning concepts of OOP.

I agree with you for the most part, however if you are after speed use MySQLi. Writing your own class can in some cases be up to three times slower than procedural programming styles. Classes still become useful when it comes to flexibility, code organization, and reusability.

For anybody that wants a decent comparison of OOP and procedural programming check out this link. http://devzone.zend.com/article/1236


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

p4plus2 wrote: [quote]system_meltdown wrote:

Yeah that's a good point, only reason I suggested creating your own is it will benefit with learning concepts of OOP.

I agree with you for the most part, however if you are after speed use MySQLi. Writing your own class can in some cases be up to three times slower than procedural programming styles. Classes still become useful when it comes to flexibility, code organization, and reusability.

For anybody that wants a decent comparison of OOP and procedural programming check out this link. http://devzone.zend.com/article/1236 [/quote]

Agreed, over-use of OOP when it's not needed just uses up resources. However I'm guessing since this guy seems pretty new to PHP, he won't care for code optimization, so writing his own class would be fine (if he thinks he can do it at least), else, go with MySQLi, it's pretty slick.


Demons Halo's Avatar
Member
0 0

system_meltdown wrote: Agreed, over-use of OOP when it's not needed just uses up resources. However I'm guessing since this guy seems pretty new to PHP, he won't care for code optimization, so writing his own class would be fine (if he thinks he can do it at least), else, go with MySQLi, it's pretty slick.

nice discussion there =D that's why I like asking questions instead of googling =D=D

The time / knowledge is not the issue here, I can spend a couple hours learning more about php, but to be honest I don't care that much about the optimization or the method itself as long as it gets the job done in the way it's suppose to. Although I gotta say that I find OOP overkill for this particular task! A config file would do just fine I guess =D


ghost's Avatar
0 0

MoshBat wrote: require_once("config.php");

Always a good decision.

Not that it really matters, but the correct syntax is: require_once "config.php";

However both work just fine.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

c4p_sl0ck wrote: [quote]MoshBat wrote: require_once("config.php");

Always a good decision.

Not that it really matters, but the correct syntax is: require_once "config.php";

However both work just fine.[/quote]

Heh, require_once is like echo and print in the sense that both:

echo "hax"; and echo( "hax" );

are the same.

So yeah, it's not "correct syntax"; however neglecting the brackets looks nicer in my opinion.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

MoshBat wrote: Once again, it's a personal choice thing.

Yep, I don't like using too many brackets and braces, and I like to tab and space everything, makes it easier to read in my opinion.


spyware's Avatar
Banned
0 0

MoshBat wrote: which saves on mere bytes

You should compare compiled/processed code.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

MoshBat wrote: [quote]system_meltdown wrote: [quote]MoshBat wrote: Once again, it's a personal choice thing.

Yep, I don't like using too many brackets and braces, and I like to tab and space everything, makes it easier to read in my opinion.[/quote] I like brackets, I like having everything compressed, such as

   print &quot;Niiice&quot;;
}else{
   print &quot;Awwh, fuck&quot;;
}```
which saves on mere bytes, and --to me-- just looks neater and more uniformed.
But I do, of course, indent appropriately. [/quote]

echo is better to use than print :p

I dislike using: if( $blah == $blah ){

I find it makes the braces harder to match up, so much easier with them on a separate line :p

p4plus2's Avatar
Member
0 0

My personal style is adapted from the coding guidelines for the linux kernel.

&lt;?php

function syntax()
{

        $tab_width = 8;
        $reason = &#39;legibility and lines stand out&#39;

        if($tab_width == 8){
                echo $reason;
                echo &#39;Line should also be kept under 80 characters when possible, however
                        I do tend to violate this rule on occasion.&#39;;
        }else{
                die(&#39;invalid tab width&#39;);
        }
}

?&gt;

function braces get there own lines, conditionals do not. It helps me determine what brace you are editing a bit faster IMO. In the linux kernel they tend to use no braces when possible, but I don't do this in php.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

MoshBat wrote: Also, milliseconds don't matter to me in terms on print/echo. We've been over this. I probably use print because of my use of Perl.

It's not just that. Due to echo's nature, it can be overloaded, so instead you can use

markupecho &quot;Hello, &quot;, $_SESSION[&#39;username&#39;], &quot;, how are you?&quot;;

Which is a shit lot faster than concatenating with dots, something you cannot do with print.

Plus, if you like to save precious bytes, you should use echo as it's one char less than print :p


ghost's Avatar
0 0

MoshBat wrote: [quote]c4p_sl0ck wrote: [quote]MoshBat wrote: require_once("config.php");

Always a good decision.

Not that it really matters, but the correct syntax is: require_once "config.php";

However both work just fine.[/quote] http://us3.php.net/manual/en/function.require-once.php Nice try. It's the other way round. Most functions are intended to have brackets around them. Quick demonstrative example:

require_once $fuck;```[/quote]

Actually, it&#39;s not. As you are referred to on the require_once page:
http://us3.php.net/manual/en/function.include-once.php
There they have this example:
```markup&lt;?php
include_once &quot;a.php&quot;; // this will include a.php
include_once &quot;A.php&quot;; // this will include a.php again! (PHP 4 only)
?&gt;

p4plus2's Avatar
Member
0 0

c4p_sl0ck wrote: Actually, it's not. As you are referred to on the require_once page: http://us3.php.net/manual/en/function.include-once.php There they have this example:

include_once &quot;a.php&quot;; // this will include a.php
include_once &quot;A.php&quot;; // this will include a.php again! (PHP 4 only)
?&gt;

Also watch out for this:

var_dump(include_once &quot;nonexistant.php&quot;); // this will dump false
var_dump(include_once &quot;nonexistant.php&quot;); // this will dump true
?&gt;

This happens because php thinks the file was already included, but as we know that is not the case. Not that this should really ever happen in the real world but I figured its worth pointing out.


ghost's Avatar
0 0

MoshBat wrote: Guys… Whomever missed my point above, example #2 of require_once, without brackets doesn't work, at least, not on my version of PHP. And you use require_once() so the same file doesn't get included twice…

I think there's some misunderstanding in this thread. What is it that's not working?


ghost's Avatar
0 0

MoshBat wrote: [quote]c4p_sl0ck wrote: [quote]MoshBat wrote: Guys… Whomever missed my point above, example #2 of require_once, without brackets doesn't work, at least, not on my version of PHP. And you use require_once() so the same file doesn't get included twice…

I think there's some misunderstanding in this thread. What is it that's not working?[/quote] Oh, nevermind.[/quote]

Thats right. Give up mosh, just give up. :p


ghost's Avatar
0 0

MoshBat wrote: [quote]S1L3NTKn1GhT wrote: [quote]MoshBat wrote: [quote]c4p_sl0ck wrote: [quote]MoshBat wrote: Guys… Whomever missed my point above, example #2 of require_once, without brackets doesn't work, at least, not on my version of PHP. And you use require_once() so the same file doesn't get included twice…

I think there's some misunderstanding in this thread. What is it that's not working?[/quote] Oh, nevermind.[/quote]

Thats right. Give up mosh, just give up. :p[/quote] Gave up explaining. [/quote]

Exactly. ;)