473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to connect to MySQL

AP
I have not seen any good examples on how to connect to a mySQL db. My
website uses phpMyAdmin to administer the SQL databases. What confuses
me is where are the databases that I create located? For example, if my
website is www.mywebsite.com and I have installed myphpadmin in the
folder tkd, now using this I have created two databases, one named
'acct' with a single table named 'persons', and another database named
'terms' with a single table named accounts. How would I specify in php
that I wanted to connect to the acct database and pull from the persons
table?

Thanks

Oct 27 '05 #1
6 1846
Phpmyadmin is a web base mysql databse administration tool, it doesn't
matter where u install it under your webroot. It helps you to
adminstrate mysql db using a web browser insted of using command line
mysql> tool.

When you create a db using phpmyadmin or in any other way, mysql stores
the data files in a directory (Data Directory) which is specified in
my.ini file.

After adding a user with appropriate privileges you can connect to
mysql localy or remotely.

If you are going to use only one table you can select that db after
connecting to mysql like,

//copy paste from php manual
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}

you can use mysql_db_query() function to send a query to terms database
while acct is selected.

You may want to look at php manuel...

Oct 27 '05 #2
yes you can use mysql_db_query function as,
............
mysql_connect($hostname, $user, $passwd);

$result = mysql_db_query($db1, $query1);
$row1 = mysql_fetch_object($result);

$result = mysql_db_query($db2, $query2);
$row2 = mysql_fetch_object($result);
.............

Oct 27 '05 #3
gd
mysql_connect($hostname, $user, $passwd);

$result = mysql_db_query($db1, $query1);
$row1 = mysql_fetch_object($result);
$result = mysql_db_query($db2, $query2);
$row2 = mysql_fetch_object($result);

Oct 27 '05 #4
Botan Guner,

I have a similar problem and I use exactly your code

//copy paste from php manual
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
<

and I get
Parse error: parse error, unexpected T_IF in
my program (or your program or the manual's program)
on line
'if (!$link) {'

Something must be wrong in my setup. Can you give me a hint?
Lennart
Oct 28 '05 #5
Lennart Björk wrote:
Botan Guner,

I have a similar problem and I use exactly your code
>

//copy paste from php manual
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
<

and I get
Parse error: parse error, unexpected T_IF in
my program (or your program or the manual's program)
on line
'if (!$link) {'

Something must be wrong in my setup. Can you give me a hint?
Lennart


Lennart,

I don't see an error there. I suspect it's someplace earlier in your
code. Probably mismatched single quotes.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 28 '05 #6
Jerry,
I suspect it's someplace earlier in your code


You are right and the error was mine. I forgot a semicolon.

Lennart
Oct 31 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " ....
0
by: Bill Hernandez | last post by:
Hi, I've been writing software on the mac since 1987, but am brand new at unix/php/mysql, and that's where I'm headed so I'm reading everything I can get my hands on, but like anything else...
0
by: Ryan Stewart | last post by:
I'm running MySQL server on a WinXP box at home. I have a cable modem/router. I've set up port forwarding on port 3306 to the machine running MySQL. I can connect locally just fine, but when I try...
3
by: Pugi! | last post by:
On a freshly installed Fedora C3 (incl. webserver apache php mysql) i get the following problem when connecting to mysql through a browser (phpMyAdmin): : #2002 Can't connect to local MySQL...
1
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
2
by: xiuchuanli | last post by:
I install Fedora 4 with web server, after that I installed mysql 5.0.15. Now I can connect to mysql from command line and mysql-administrator and mysql-query-browser. But when I try to test to...
0
by: xiuchuanli | last post by:
I install Fedora 4 with web server, after that I installed mysql 5.0.15. Now I can connect to mysql from command line and mysql-administrator and mysql-query-browser. But when I try to test to...
1
by: linux | last post by:
Sorry if this is a really dumb question. I am trying to connect to our remote MySQL server (which is running just fine). I have a perl script which worked just fine on my other Fedora 4 box (all...
2
by: Martin | last post by:
Hi all. I have a fully functional page hosted on my PC that uses PHP and connects to MySQL on my PC to generate it's code. I now have some web hosting available which includes both PHP and...
5
by: scorpionbilli | last post by:
Hi, The local mysql server is running on my Macbook. I can access it through the console client: $ mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.