Reply
My first steps with MySQL sucks! Help needed!
Old 07-09-2004, 11:14 AM My first steps with MySQL sucks! Help needed!
Junior Talker

Posts: 3
Hello!

I try to start doing some basic MySQL but it just wont work.
I've read thru some basic manuals but the problems are awesome.

So far it looks like my server is working, the PHP is doing fine, even the database is somewhere out there but I cant fetch the data...

Here is my simplified attempt to write and read.

All help welcome! If you have the time list up the errors for me.


<?
$user="xxx";
$password="xxx";
$database="xxx";

mysql_connect("mysql",$user,$password);
mysql_select_db($database) or die( "Unable to select database");

// first we create the table, with three fields

mysql_query("CREATE TABLE chat (one, two, three)");

// ... and now we write

mysql_query( "INSERT INTO chat VALUES ('Paul','John','Smith')" );

// ...and now we try to read

$query="SELECT * FROM chat";
$result=mysql_query($query);

$a=mysql_result($result,"0", "one");
$b=mysql_result($result,"0", "two");
$c=mysql_result($result,"0", "three");

// here we print the result

echo "$a $b $c<br>";
mysql_close();
?>
Dunkel is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-09-2004, 11:32 AM
Average Talker

Posts: 25
Location: UK
I use something like this:-

if($result)
{
while($row = mysql_fetch_array($result))
{
echo("ID: " .$row["id"]);
echo(" - NAME: " .$row["name"]);
echo(" - NUMBER: " .$row["number"]);
}
}

Nick
nickc is offline
Reply With Quote
View Public Profile Visit nickc's homepage!
 
Old 07-09-2004, 12:53 PM
Junior Talker

Posts: 3
Quote:
Originally Posted by nickc
I use something like this:-
...


Yes, I see. But my problem is that I don't know where I do wrong. That's why I have simplified and done as linear as possible my example...

There's some or more basic errors I do because I just don't get it. Should the example in the beginning of this thread work? If not, then what should I correct?
Does it even appear what it should do, hah haa.

Dunkel
Dunkel is offline
Reply With Quote
View Public Profile
 
Old 07-09-2004, 01:49 PM
compmodder26's Avatar
Experienced Talker

Posts: 44
Quote:
mysql_connect("mysql",$user,$password);
This is probably why you can't connect to your database. This particular function has the sytax of :

PHP Code:
mysql_connect (hostname,usernamepassword); 
Unless your MySQL server is named "mysql" you can't connect this way. If the server is on your own machine then just use "localhost" as the hostname. If it doesn't exist on your own machine you'll have to use the IP address or ask the server administrator to supply you with the hostname.
compmodder26 is offline
Reply With Quote
View Public Profile Visit compmodder26's homepage!
 
Old 07-09-2004, 02:03 PM
Junior Talker

Posts: 3
Quote:
Originally Posted by compmodder26
...Unless your MySQL server is named "mysql" you can't connect this way. If the server is on your own machine then just use "localhost" as the hostname. ...
In fact the server is named "mysql" but I will double check that.

I have now copied, edited and writed and test drived a dozen of examples (and will continue with that) and everything goes error free until I try to read the database. Nothing dramatic but I just don't get any data out.

Is there somewhere a VERY SIMPLE example how to create, write and read a database? I mean real simple, something that I can deal with.
Dunkel is offline
Reply With Quote
View Public Profile
 
Old 07-09-2004, 03:16 PM
compmodder26's Avatar
Experienced Talker

Posts: 44
try doing:

PHP Code:
$link mysql_connect("mysql",$user,$password) or die(mysql_error());
mysql_select_db($database$link) or die( "Unable to select database");

// first we create the table, with three fields

mysql_query("CREATE TABLE chat (one, two, three)"$link);

// ... and now we write

mysql_query"INSERT INTO chat VALUES ('Paul','John','Smith')"$link);

// ...and now we try to read

$query="SELECT * FROM chat";
$result=mysql_query($query$link);

$a=mysql_result($result,"0""one");
$b=mysql_result($result,"0""two");
$c=mysql_result($result,"0""three");

// here we print the result

echo "$a $b $c<br>";
mysql_close();
?> 
compmodder26 is offline
Reply With Quote
View Public Profile Visit compmodder26's homepage!
 
Reply     « Reply to My first steps with MySQL sucks! Help needed!
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13621 seconds with 12 queries