What is a DataSource(Connecting to MySqL)?
am 21.08.2006 05:07:36 von Nobody
Hello,
Im new to PHP and Databases. I created a MySQL db, installed phpMyAdmin
and created a table and single field. I created a small PHP script. The
PHP Script (called from a FORM action) is supposed to take the email
field in the form and store it in the MySQL db. I obtained the
mysql_connect()parameters from my ISP's Control Panel DBsection. However
the PHP script is returning a "Could not Connect" message. (this is
built into the PHP script - see snippet below):
$connection = mysql_connect("localhost","username","password");
if (!$connecttion) {
die ("Could not connect: " . mysql_error());
}
echo "Connected";
My ISP mentioned I might need to create a datasource to connect to the
db. I found some info in their knowledge base, and started to creat one.
I created a dataSource name, and It generated a text string in the form:
"dsn=datasourcename;uid=XXXX;password=XXXX"
I placed the string in the mysql_connect() Statement but it isnt
working. Is there a special statement in PHP for DataSource Names? What
is a datasource and why do I need one? Why aren't the original supplied
parameters sufficient? Thank you for your time and words for this
database newbie.
George
P.S. No answers from my ISP provided DB forum so I fiigured I try here.
-------------------------------
http://www.gpalzproductions.com
"The world is full of Kings and Queens who blind your eyes and steal
your dreams. Its Heaven and Hell!" - Ronnie James Dio
Re: What is a DataSource(Connecting to MySqL)?
am 21.08.2006 17:57:11 von chrisv
Quick question:
who is your isp?
some hosted/managed isps can have quirky database access rules. for
instance, i have several bluehost.com accounts. when i use CREATE
testdb from the command line, it is created on the bluehost 'localhost'
server with no problem. but, bluehost appends a small string from your
account name in front of my database name for their purpopses. so if
my account name is happy_blue_host_client, my 'testdb' name becomes
'happy_blue_testdb". i didn't know this at first and got serveral
script errors when i first opened my accounts. now its not an issue.
so read your isp's documentation because there could be special rules
for connecting to you mysql database.
this may be obvious, but i have to ask because i assume nothing about
you. did you replace 'username' and 'password' with the mysql username
and password you assigned to your mysql database instance?
nobody@thisaddress.net wrote:
> Hello,
>
> Im new to PHP and Databases. I created a MySQL db, installed phpMyAdmin
> and created a table and single field. I created a small PHP script. The
> PHP Script (called from a FORM action) is supposed to take the email
> field in the form and store it in the MySQL db. I obtained the
> mysql_connect()parameters from my ISP's Control Panel DBsection. However
> the PHP script is returning a "Could not Connect" message. (this is
> built into the PHP script - see snippet below):
>
> $connection = mysql_connect("localhost","username","password");
>
> if (!$connecttion) {
> die ("Could not connect: " . mysql_error());
> }
> echo "Connected";
>
> My ISP mentioned I might need to create a datasource to connect to the
> db. I found some info in their knowledge base, and started to creat one.
> I created a dataSource name, and It generated a text string in the form:
>
> "dsn=datasourcename;uid=XXXX;password=XXXX"
>
> I placed the string in the mysql_connect() Statement but it isnt
> working. Is there a special statement in PHP for DataSource Names? What
> is a datasource and why do I need one? Why aren't the original supplied
> parameters sufficient? Thank you for your time and words for this
> database newbie.
>
> George
>
> P.S. No answers from my ISP provided DB forum so I fiigured I try here.
>
>
> -------------------------------
> http://www.gpalzproductions.com
>
> "The world is full of Kings and Queens who blind your eyes and steal
> your dreams. Its Heaven and Hell!" - Ronnie James Dio
Re: What is a DataSource(Connecting to MySqL)?
am 22.08.2006 04:26:25 von Nobody
Yep, I did replace the username and password with the actual MySqL UN
and PW. One of the administrators in the forum was kind enough to take a
look at my script. Waiting to hear back.
My ISP is CrystalTech.com. I checked their knowledge base for
assistance. Found an article on Connection Strings(see below) but it
shows the standard mysql_connect() format(which I used) and isnt all
that clear on how to use the generated Datasource string.
Hopefully the Administrator will see something in the PHP. Its funny how
nobody on the forum responded. I would have figured connecting to MySQL
from PHP was consistent. I can see that may not be the case from ISP to ISP.
Subject: Connection Strings For MySQL
Article #656
If needed, create a DSN (DataSource) by logging into the Control Center
at..... ....and from the menu item DATABASE clcik on DATASOURCE
Next, use one of the following connection string formats that
corresponds to the platform used in the code of the website.
PHP (DSNless):
$db = mysql_connect("mysql#.XXXXX.com", "user", "pass")
** Where mysql#.XXXXXX.com you would need to replace the # with the
number of your MySQL server which can be found from the menu item
DATABASE select MYSQL and click on MY SQL ADMIN in the Control Center
chrisv wrote:
> Quick question:
>
> who is your isp?
>
> some hosted/managed isps can have quirky database access rules. for
> instance, i have several bluehost.com accounts. when i use CREATE
> testdb from the command line, it is created on the bluehost 'localhost'
> server with no problem. but, bluehost appends a small string from your
> account name in front of my database name for their purpopses. so if
> my account name is happy_blue_host_client, my 'testdb' name becomes
> 'happy_blue_testdb". i didn't know this at first and got serveral
> script errors when i first opened my accounts. now its not an issue.
> so read your isp's documentation because there could be special rules
> for connecting to you mysql database.
>
> this may be obvious, but i have to ask because i assume nothing about
> you. did you replace 'username' and 'password' with the mysql username
> and password you assigned to your mysql database instance?
>
>