473,666 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1857
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_obj ect($result);

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

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

$result = mysql_db_query( $db1, $query1);
$row1 = mysql_fetch_obj ect($result);
$result = mysql_db_query( $db2, $query2);
$row2 = mysql_fetch_obj ect($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*******@attgl obal.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
4803
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: " . mysql_error()); echo "Connected successfully"; mysql_close($link);
0
2404
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 there's going to be a learning curve, that having been said... I followed the install instructions at http://entropy.ch , and was able to get mySql & php installed on my G4 -> (OSX 10.2.6) last night. I downloaded Navicat and setup a password for...
0
9006
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 to connect from a remote location using: mysql -h xxx.xxx.xxx.xxx -P 3306 -u root -p mysql I get: ERROR 2003: Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (10061) When I try:
3
17795
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 server through socket /var/lib/mysql/mysql.sock On the website of MySQL this error is mentioned but I found no solution. In /var/log/messages the following log occurs :
1
121524
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 alpha) so I deinstall mysql5-server and mysql5-client And then I install mysql41-server and mysql41-client on FreeBSD 5.3 by ports but now , mysql is not workable
2
2738
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 connect from php code, it told me that "can not connect to local mysql through /tmp/mysql.sock. /tmp/mysql.sock is my sock file to connect and permission is set good. when I add phpinfo() to my php code, it show me that mysql lib php uses is 4.1.X,...
0
1818
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 connect from php code, it told me that "can not connect to local mysql through /tmp/mysql.sock. /tmp/mysql.sock is my sock file to connect and permission is set good. when I add phpinfo() to my php code, it show me that mysql lib php uses is 4.1.X,...
1
4500
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 servers are Fedora 4 with latests updates). The one that worked fine it down and I cannot compare anything against it (it was a client also). My problem is, when I try to connect to the server I get:
2
22535
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 MySQL support, however the webhost is still in the process of getting the MySQL support activated and functional. I therefore have uploaded my webpage to the host and edited the webpage
5
2622
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 connection id is 4 Server version: 5.0.45 MySQL Community Server (GPL)
0
8440
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8866
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.