Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


mysql_connect question

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 3:26 pm    Post subject: mysql_connect question Reply with quote

Ok I understand what this function does. But I have a question about it. I understand MySQL is a data base, but it's the parameters I don't get. Like if I'm running a website of my computer that has user accounts or something and I'm storing it in a MySQL database does MySQL let you specify what the name, the user, and pass should be during installation? And what if there's a data base with more than one name (or does that not happen)? By the way, when do I execute this code...

Code:

<?php
//I know I don't have any error handling so don't tell me
$con = mysql_connect("localhost", "user", "pass");
mysql_query("CREATE DATABASE my_db", $con);
$sql = "CREATE TABLE accounts
(
   accountsID int NOT NULL AUTO_INCREMENT,
   username varchar(30),
   password varchar(16)
)";
mysql_query($sql, $con);
mysql_close($con);
?>


Do I just one it once from my computer then edit it out of the file that references it?

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Thu Jul 10, 2008 3:35 pm    Post subject: Reply with quote

Your question is VERY VERY confusing...

Are you running a server on your computer? or what are you doing...

That script is used to connect to a MySQL database... You need it in ever PHP script.. that is why i like to make 1 file that just has that in it. and put in

include('connect.php');

Every time it is included it will connect... then usually you need to run a query and a way to fetch the query then you can easily to whatever you want with it.

Hope that helps Smile

If you are running your own server DONT DO IT... to much hassle... Just go to

x10hosting.com

and get free hosting... then you dont have to worry about databases and administration and all that tough stuff.

_________________
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 3:50 pm    Post subject: Reply with quote

Well, I just plan on hosting a small website from my computer. And I was gonna install apache, and mysql and php and stuff. But my question was that in the code:

Code:

$con = mysql_connect("localhost", "user", "pass");


How do I know what to put for the servername, username, and password. When I install MySQL does it let me specify that, so I know? And I was also asking when to execute the part that creates the database and table.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Thu Jul 10, 2008 4:17 pm    Post subject: Reply with quote

1) localhost is what you will use most of the time... unless you are using a remote MySQL database ( no )

2) USually you get to define what the username and password is... im not sure, read the MySQL documentation, it has nothing to do with PHP

3)Check out my new guide on MySQL + PHP on my tutorial page!

_________________
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 5:39 pm    Post subject: Reply with quote

If localhost is used most of the time than how do you know which server to connect to. And what is the difference between a remote MySQL database and a normal (or so I assume) one?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Thu Jul 10, 2008 5:45 pm    Post subject: Reply with quote

if the file is on localhost and the mysql server is also on localhost, the name of the serverhost in the php has to be localhost!

Only time you would change it is if the MySQL database is on a different server ( this usually never happens, it is basically a computer devoted to just MySQL... )

Dont worry about it... its localhost.

Check out my new tut

_________________
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 6:21 pm    Post subject: Reply with quote

Oh, I get it now! Localhost is kind of like a Private IP address. Say you have two computers on different networks that both have the IP 192.168.1.106. Because they're on different networks it's a private IP, so they can both have the IP address 192.168.1.106. Localhost is the same right?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Localhost
I post too much
Reputation: 0

Joined: 28 Apr 2007
Posts: 3402

PostPosted: Thu Jul 10, 2008 7:31 pm    Post subject: Reply with quote

192.168.1.x : usually thats what the "private" ip of your computer looks like... Computer A on your router would probably have something like 192.168.1.101 or something like that, Computer B with 192.168.1.102... No two computers on your router have the same private IP...

If you type in localhost on Computer A you wont go to the same localhost as computer B... Localhost = private IP...

Dont worry your head about it, seriously.

_________________
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 8:15 pm    Post subject: Reply with quote

No I'm saying if you have two computers on different networks they can have the samse IP address because they have a private one (i.e 192.168.1.106). But yeah, I get it now.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Thu Jul 10, 2008 9:22 pm    Post subject: Reply with quote

localhost / 127.0.0.1 is standard for loopback which will connect the computer to itself. If you are using an SQL database that is on your system, just use 'localhost' in anything that requires a host.

Quote:
Ok I understand what this function does. But I have a question about it. I understand MySQL is a data base, but it's the parameters I don't get. Like if I'm running a website of my computer that has user accounts or something and I'm storing it in a MySQL database does MySQL let you specify what the name, the user, and pass should be during installation? And what if there's a data base with more than one name (or does that not happen)? By the way, when do I execute this code...


MySQL asks for a username / password for root when you install it. If you didn't see the prompt for it, or don't remember the password you can reconfigure it. In the start menu should be a folder for MySQL, and inside that should be a service configuration icon. Use that to reconfigure the service.

Quote:
Do I just one it once from my computer then edit it out of the file that references it?


Any page that requires information to or from the database must have a valid connection. You can create a simple include to connect for you so instead of rewriting the connection code in any file that needs a connection, you can simply include the php file that will do the work for you. (Be sure to cleanup the connection that is created.)

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 10:20 pm    Post subject: Reply with quote

Nono not the connect part, but this part.

Code:

mysql_query("CREATE DATABASE my_db", $con);
$sql = "CREATE TABLE accounts
(
   accountsID int NOT NULL AUTO_INCREMENT,
   PRIMARY KEY(accountsID),
   username varchar(30),
   password varchar(16)
)";
mysql_query($sql, $con);


Because I only want this to happen once. So should I put it in a file and execute it and then just delete it (the file and any reference to it)?

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Jul 10, 2008 10:24 pm    Post subject: Reply with quote

You can do that manually in the MySQL console window, no need for PHP.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Jul 10, 2008 10:26 pm    Post subject: Reply with quote

REALLY? YAY!
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Fri Jul 11, 2008 6:42 am    Post subject: Reply with quote

When you create a table, that should be done either once via a single SQL connection (without PHP) or use a control panel like phpMyAdmin. You can use PHP to do it if you want but you don't need to. During runtime there's really no reason to constantly be creating tables.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites