FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


MySQL and Php





Billwaa
Hi guys, I am starting to learn php, and now I want to learn how to use that with MySQL. Can anyone tell me how MySQL really work and how to use it with php? Thanks.

By the way, after I learned how to use it, I will attempt to make a simple browser multiplay game. I will post more after I learn it...
kenetix
Maybe this helps:
http://www.mysql.com/
http://en.wikipedia.org/wiki/Mysql
Atomo64
connect:
Code:
<?php
if(($sql_connection=mysql_connect($hostname,
      $username,
      $password))==false)
die( "Error # ".mysql_errno().":&nbsp;".mysql_error());

if(mysql_select_db($db,$sql_connection)==false)
die( "Error # ".mysql_errno().":&nbsp;".mysql_error());
?>


let's say that we have a 'fruits' table, with the next fields: name, left, price
now let's do something... let's think that it is a shop script
Code:

<?php
$fruit=mysql_real_escape_string($_GET["fruit"],$sql_connection);
$query="SELECT * FROM `table` WHERE 'name' = '$fruit'";
$result=mysql_query($query);
if($result===false)
die( "Error # ".mysql_errno().":&nbsp;".mysql_error());
if($result==false)
die("Sorry, we don't have that fruit");
$fruit_data=mysql_fetch_assoc($result);
mysql_free_result($result);
echo "How many ".$fruit_data['name']."s do you want? ".($fruit_data['left']>20)?"":" we only have ".$fruit_data['left'].". It is \$".$fruit_data['price']." per unit.";
?>
Billwaa
thanks, that help me out a bit. Very Happy

so I have to define the variable

$hostname

$username

$password

in the beginning right?

I am just not too sure what $hostname is, is it the host address?
vinx_18
Yup...the $hostname is the host address....Sample: $hostname = localhost....$username is the username of your database ...$password is the password of your database....You could also directly put your hostname,username,password...in the mysql_connect function....
Atomo64
yup, that's it, but I just added those variables so you can understand well Smile
and $hostname can be an IP, or even a domain name
Billwaa
should I use this adress as webhost address if I use FriHost?

http://www.wazs.frih.net:2222/

or this one?

http://216.32.85.170/
InjunMick
try this one
http://www.wazs.frih.net

InjunMick
mathiaus
using localhost is your bestbet Wink
Atomo64
and btw, you don't have to add the http:// (nor any other protocol specification), just the domainname or the IP
aviva
thanks
Billwaa
aviva wrote:
thanks


is that a spam?

*Oh yeah, guys, I am looking at the code got a bit confuse but got something out of it. Is there a step by step instruction thing?
westsida
hey guys im just trying to score some points so i can start uploading my website to the ftp server lolz..
westsida
hey what's the cheapest domain you guys have seen?
KRONIC
hey guys i am a novice in php right now. i am now beggining to learn about it. i have one question.

how do you turn off the safe_mode?
Atomo64
KRONIC wrote:
hey guys i am a novice in php right now. i am now beggining to learn about it. i have one question.

how do you turn off the safe_mode?

by editing the php.ini file, which in most(if not on all) free hostings is not possible to have access to it.
Related topics
Where can I find tutorials for MySQL?
Seeking MySQL-php-Apache installer for WinXP
PHP DB Error: syntax error
How to install PHP and Apache in 5 min on Win98
mysql/php help please
server with ready PHP
MySQL, PHP and APACHE
[ Newbie; Makin pages, mySQL, PHP, etc ]
[ Newbie; Makin pages, mySQL, PHP, etc ]
Is mySQL/php in safe mode on Frihosting?
PHP&MySql - Is there any server side caching of queries?
apache php and mysql on mac OS X
MySQL [php Mail()] and FriHost Mass mail rules
Setting up a local PHP and MySQL Workspace
What to learn first?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.