| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | connecting to db..running a query Hey i am reading an ebook on php and mysql..and here is how they teach to connect to a db: ????: NamePros.com http://www.namepros.com/programming/277976-connecting-to-db-running-a-query.html PHP Code: PHP Code: this is how they tell to run a query: PHP Code:
__________________ |
| |
| | #2 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | If you are using multiple databases, you need to use a variable (such as $conn.) Otherwise, I don't think you need it. echo $conn; would give you an error, too. The ", $conn" in your third code doesn't need to be there. I don't know about $sql, because I'm not good at doing CREATE's in queries, but as far as I can tell, it's right. |
| |
| | #4 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | You'll get "Resource link identifier" or something if you try to do "echo $conn;". It's not really an error, but it's not really not an error. I don't think using the MySQL link variable into the query does anything to do unless you are accessing multiple databases. I wouldn't worry about using it in queries, however I still would give the mysql_connect() a variable. |
| |
| | THREAD STARTER #5 (permalink) | ||||
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
__________________ | ||||
| |
| | #6 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | PHP Code: |
| |
| | #8 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | That's what "$conn" is for. You would do $conn = mysql_connect... then something like $conn2 = mysql_connect... To query the first database, you'd use mysql_query($query, $conn) and to query the second, you'd just use $conn2. |
| |
| | THREAD STARTER #10 (permalink) |
| Senior Member Join Date: May 2005 Location: Ontario Canada
Posts: 3,088
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | Hey I need this now..and i cant figure it out the $conn stores the user information..not the database so how do u tell it 2 use a specific database? right now i m working a script where users can make and edit databases..and 1 is the Main database that they are using almost all the time..and then there are Databases that they make/edit/delete etc.. right now to connect and run a query i have PHP Code: ????: NamePros.com http://www.namepros.com/showthread.php?t=277976 P.S: this is in a class..if it makes any difference
__________________ |
| |