|
|
|
| Web Hosting Guide |
![]() ![]() |
Important: Basics Of Using PHP And MySQL |
May 26 2006, 06:30 PM
Post
#1
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
I generally notice confusion with new users to PHP and or MySQL and first of all I believe that unlike HTML which is automatically associated with a IE browser in a Microsoft system. HTML is automatically rendered with whatever browser is the default browser, be it Internet Expolrer Firefox Netscape or any other browser that has been set.
PHP is a different matter to view the output of a PHP file it must be run on a webserver, and if you do not have one set up on your local PC it simply will not work. (Note serverside langauge requies a server) HTML is client side and requires only a browser so it will display by double or single clicing the file itself and the program associated with it will open it, but not so with PHP or ASP (Window servers only) or Perl. You must have a working webserver like IIS PWS Apache Solaris and so on, and the file must be accessed with a browser that sends a request for a page that resides on the server like one of the above mentioned. All webservers have a ROOT where they keep files and other subdirectories. Normally you will have an index.html or index.php file (the server looks for these type files and serves them upon request of that file. With a PHP file the server will look up what you typed into to address bar and try to PARSE it (unlike HTML) to do whatever it is supposed to do, if PHP is not set up properly it will produce either errors or unexpected results or both. The webserver must know where the executable file is and this is set up in the servers sonfiguration file, then there are dlls that the PHP or other langauge will need to perform certain operations when asked to do so, if these are not set they will fail with errors. If you are using astahost as a server usually you do not need to worry about this, but if you have some ideas about creating something that requires PHP on you site it would be best to place a webserver on your home PC or MAC and develop these programs there and when debugged to the point where you are satisfied then upload them to astahost. I am a regular contributor to PHP Builder Forums and Dev Shed here and see these question all the time, I used to answer and try to help, but now it seems that installation of these services. My PAT answer anymore is to just download and install either XAMPP available here or you could use WAMP available here This is not a tutorial but a post to try to help those that are new to PHP to get started in the right direction. While it is possible to install a server and MySQL and PHP on your own (with much frustration and questions) the programs I suggested will help you if all you really want to do is write PHP and MySQL routines to develop a site. This is just my opinion for newbies and I am sure that there will be those that tell me you should actually learn something from doing it on your own, but when I see people getting more and more confused trying to do this then I really wonder if the satisfaction of self installation is really that much a benefit unless that is your desired career. |
|
|
|
May 26 2006, 10:43 PM
Post
#2
|
|
|
Premium Member Group: Members Posts: 302 Joined: 23-February 06 From: Northeastern Connecticut USA Member No.: 11,487 myCENTs:38.43 |
See thats where I think Im making my mistake. I have Xammp installed on machine, but the main reason I did it was so I could see PHP (so I thought). I have been doing all my coding straight on my Astahost site. Now I know that I should be doing it through Xammp first.
|
|
|
|
May 27 2006, 11:33 AM
Post
#3
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
Correct, you (or at least I) should develop your new code on your localmachine and when it is working the way you want it to work then upload the now hopefully bug free script up to your working site. Another thing I do with new scripts is have two folders on the internet site one with my real content and another (call it test or something like that) if the script does something wrong or worse (it wrecks your site) then you can correct it while your real site goes merrily along.
The only difference you would have is a config.php file, one for your local machine like below CODE <?php and for your astahost it would be something like$host="localhost";//this is default $user="root";//this is a default for a new MySQL $pass="";//this is the default (no password for 'root') $connect=mysql_connect($host,$user,$pass) or die("Could not connect to server, MySQL said: ".mysql_error()); ?> CODE <?php
$host="localhost": $user="yourastahostusername"; $pass="yourastahostpassword": $connect=mysql_connect($host,$user,$pass) or die("Could not connect to server, MySQL said: ".mysql_error());//good to check for errors ?> |
|
|
|
May 29 2006, 09:19 PM
Post
#4
|
|
|
Super Member Group: [HOSTED] Posts: 876 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:13.21 |
QUOTE(Houdini @ May 27 2006, 06:33 AM) [snapback]79307[/snapback] Correct, you (or at least I) should develop your new code on your localmachine and when it is working the way you want it to work then upload the now hopefully bug free script up to your working site. Another thing I do with new scripts is have two folders on the internet site one with my real content and another (call it test or something like that) if the script does something wrong or worse (it wrecks your site) then you can correct it while your real site goes merrily along. The only difference you would have is a config.php file, one for your local machine like below CODE <?php and for your astahost it would be something like$host="localhost";//this is default $user="root";//this is a default for a new MySQL $pass="";//this is the default (no password for 'root') $connect=mysql_connect($host,$user,$pass) or die("Could not connect to server, MySQL said: ".mysql_error()); ?> CODE <?php $host="localhost": $user="yourastahostusername"; $pass="yourastahostpassword": $connect=mysql_connect($host,$user,$pass) or die("Could not connect to server, MySQL said: ".mysql_error());//good to check for errors ?> Excellent suggestions and congratulations for the first post, i think its very helpful for all newbies. A time ago i installed WAMP in my PC for testing and the results were great the only thing was it installs by default other software that i dont need and were very dificult to uninstall. In my case i always like to install by hand PHP, MySql and APACHE in my win 2kpro SP4 machine to have absolute control over this software with great results, when i was a newbie i had a lot of troubles :-( that cost me a lot of time but this help me at the same time a lot. BTW, the above code dont have any code to select a database to use, so, to complete it its necesary to include first a variable with the name of the database and this in both cases: CODE $database="databasename"; my_sql_select_db($database) or die("Error... no database selected, MySQL said: ".mysql_error()); Best regards, |
|
|
|
May 29 2006, 09:39 PM
Post
#5
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
There is a reason for that include not selecting a database, and it is because I test IPB and PHP-Nuke with phpbb2 and phpbb2 (standalone BBS) and other software. If I included a database in my include file then it would be useless because it would only connect to that particular database, in my case it makes no sense and if I can't just do
CODE <?php If the code were in the confines of one particular script then it might make sense but as a contributor to a couple of PHP and MySQL related websites, sometimes I need to create a database similar to the one that they have and to see what kind of problems they are having and be able to solve it I will create a database and then run their code after removing the obvious errors to either find the problem with their code or fix it by seeing a simple error.include("connect.php"); $select=mysql_select_db("ipb",$connect) or die("Could not delect database ipb MySQL said: ".mysql_error()); //more code... ?> Does that make sense to you? This post has been edited by Houdini: May 29 2006, 09:40 PM |
|
|
|
May 30 2006, 12:30 AM
Post
#6
|
|
|
Super Member Group: [HOSTED] Posts: 876 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:13.21 |
QUOTE(Houdini @ May 29 2006, 04:39 PM) [snapback]79551[/snapback] There is a reason for that include not selecting a database, and it is because I test IPB and PHP-Nuke with phpbb2 and phpbb2 (standalone BBS) and other software. If I included a database in my include file then it would be useless because it would only connect to that particular database, in my case it makes no sense and if I can't just do CODE <?php If the code were in the confines of one particular script then it might make sense but as a contributor to a couple of PHP and MySQL related websites, sometimes I need to create a database similar to the one that they have and to see what kind of problems they are having and be able to solve it I will create a database and then run their code after removing the obvious errors to either find the problem with their code or fix it by seeing a simple error.include("connect.php"); $select=mysql_select_db("ipb",$connect) or die("Could not delect database ipb MySQL said: ".mysql_error()); //more code... ?> Does that make sense to you? Of course it make sense, and i think that a more general way to do the database selection is by using an universal function with the database name as a parameter. best regards, |
|
|
|
May 30 2006, 01:26 AM
Post
#7
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
Do you mean by generalized like the MySQLI function of
CODE $connect=mysqli_connect($host,$username,$password,$database); That is pretty general and available with newest (or newer versions of MySQL) of PHP 5 but it will not work when in fact instead of selecting test_anita datbase instead of whoknows database so writing such a connection include would not help me at all. It is not like I have to query just one database, it could be any number of them even if I just need to connect to an existing one or create another new one. This post has been edited by Houdini: May 30 2006, 01:27 AM |
|
|
|
May 30 2006, 08:45 AM
Post
#8
|
|
|
the Q Group: [HOSTED] Posts: 1,355 Joined: 13-July 05 From: Lithuania, Vilnius Member No.: 7,059 myCENTs:82.09 |
I have the problem when people mistaken HTML with PHP all the time, I am sitting on IRC channels like #phphelp, #mysql and etc. on freenode and my own country irc server. I ask for support and give my support if I have the time and can and a lot of (in my opinion stupid) people come and ask why php is better than html. I used to point them to the truth how the things works, but now I usually put a big grin or a smile, sometimes ban them if they are irritating. In fact, I think those kind of people are lazy and can't read a little on how it is, I also usually say use google, but sometimes those guys say "what kind of support it is if you only can put a smile or say use google or read the php manual and even can start swearing" but why should I answer stupid questions ? I am not paid for that, all I want to do is help with serious problems.. I think you got the point, that most of those kind of people won't even bother to read the first post of this topic - this is the real problem.
QUOTE(TavoxPeru @ May 30 2006, 03:30 AM) [snapback]79562[/snapback] Of course it make sense, and i think that a more general way to do the database selection is by using an universal function with the database name as a parameter. best regards, In my opinion, the best way is to create a database class, for example class Database { code } and call it $Database = new Database; and play with all the functions in it by using $Database->getContent($var); or call the values of the variables inside the class $Database->mError; |
|
|
|
May 31 2006, 01:21 AM
Post
#9
|
|
|
Premium Member Group: Members Posts: 292 Joined: 15-December 04 Member No.: 1,768 |
Use a Database Interface class. There are several available and keeps everything nicely organized. However you will still have to include a file that creates your database class ..or simply re-declare your database object in every script.
I think the include method is a nice way to accomodate everything. Especially if you're working on personal stuff. I'm not too familiar with working with large-scale site, but I use a Pearl-like dbi to handle all of my database calls. Just connect once in an include file, and make reference to the database handle inside my scripts that need to interact with the db. There's one dbi mentioned on here, and it might be worth looking into. Adodb or something like that. It looks like a very nice dbi to standardize all your db calls no matter the database. |
|
|
|
May 31 2006, 06:05 PM
Post
#10
|
|
|
Super Member Group: [HOSTED] Posts: 876 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:13.21 |
QUOTE(minnieadkins @ May 30 2006, 08:21 PM) [snapback]79636[/snapback] Use a Database Interface class. There are several available and keeps everything nicely organized. However you will still have to include a file that creates your database class ..or simply re-declare your database object in every script. I think the include method is a nice way to accomodate everything. Especially if you're working on personal stuff. I'm not too familiar with working with large-scale site, but I use a Pearl-like dbi to handle all of my database calls. Just connect once in an include file, and make reference to the database handle inside my scripts that need to interact with the db. There's one dbi mentioned on here, and it might be worth looking into. Adodb or something like that. It looks like a very nice dbi to standardize all your db calls no matter the database. I agree, use a database interface class is the best option in my opinion, and for that in all my future development i will -must- use someone, a few days ago i test the PEAR:DB class, and is very easy to use. best regards, |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
9 | Burgin | 2,426 | 14th March 2010 - 04:41 PM Last post by: iG-vairam |
|||
![]() |
4 | HannahI | 154 | 1st March 2010 - 12:34 AM Last post by: magiccode9 |
|||
![]() |
2 | 8ennett | 152 | 25th February 2010 - 11:42 AM Last post by: 8ennett |
|||
![]() |
7 | Jonnyabc | 176 | 17th February 2010 - 08:31 AM Last post by: mastercomputers |
|||
![]() |
3 | clovis | 1,455 | 15th February 2010 - 12:17 PM Last post by: iG-zet |
|||
![]() |
7 | kenjvalip | 2,726 | 13th February 2010 - 02:28 PM Last post by: magiccode9 |
|||
![]() |
10 | nakulgupta | 2,895 | 12th February 2010 - 06:25 AM Last post by: iG-Nancy Johnson |
|||
![]() |
4 | Manu Dhanda | 1,189 | 6th January 2010 - 12:39 PM Last post by: iG-medhatalbashaa |
|||
![]() |
10 | jedipi | 6,135 | 27th December 2009 - 11:44 AM Last post by: iG-marc |
|||
![]() |
19 | lonebyrd | 4,223 | 1st November 2009 - 03:49 PM Last post by: iGuest |
|||
![]() |
27 | nightfox | 7,368 | 14th October 2009 - 07:15 AM Last post by: iG-Mark |
|||
![]() |
3 | darkken | 2,857 | 11th September 2009 - 08:26 PM Last post by: iGuest |
|||
![]() |
6 | ruben | 1,757 | 27th August 2009 - 09:07 AM Last post by: iG-J vincent |
|||
![]() |
4 | miCRoSCoPiC^eaRthLinG | 7,081 | 21st August 2009 - 01:59 PM Last post by: iG-J vincent |
|||
![]() |
9 | bakr_2k5 | 2,024 | 29th July 2009 - 11:02 PM Last post by: iG-Wicky |
|||
|
Lo-Fi Version | Time is now: 16th March 2010 - 08:56 PM |
© 2010 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



May 26 2006, 06:30 PM






