Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




How Do I Select A Database In A Mysql Connection Script?


How can i do this in one line of code?

I know that there is:

$con = mysql_connect("localhost","user","pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

but I was unable to select a database using:

mysql_select_db("db", $con);

Any ideas?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Connection To MYSQL Database
I am new to the forum and have little experience of using MYSQL, PHP and Apache.

I am wanting to create a database or try to get the example of the "Pet Shop Catalogue" in the PHP and MYSQL dummies book to work first before I try developing my own database. Each time it comes up with an error of "Cannot connect to the database." I have entered the SQL for the example in the program given in the book, made sure that PHP is working and Apache Web page is up and running and MYSQL server is running in the back ground.

Also I tried to enter the SQL directly into the server but to no avail. Below shows the status of the MYSQL server.

mysql Ver 11.18 Distrib 3.23.52 for pc-linux -gnu (i686)
connection id 1
current database
current user root@localhost
current pager stdout
using outfile ' '
server version 3.23.52
protocol version 10
connection Localhost via UNIX socket
client characterset latin1
server characterset latin1
Unix socket /var/lib/mysql/mysql.sock

Threads 1 Questions 2 Slow Queries 0 Opens 6 Flush Tables 1 Open Tables 0 Queries per second avg 0.009

How Many Connection Can A MySql Database Handle Per Second.
I am using a MySql database for chat application.

Every 3 seconds the database is searched for various details.

I would like to know How many individual can it handle at a time.

Say there are 6 users each making a call in 3 second So every second 2
connections are made to database.

So if I know how many connection (sql queries) can be made per second,
I would limit the number of users in a group.

Mysql Database Connection - How To Make Connectin?
i have two website . both hosted on diff. server

now what i need is to connect second website database from first website
***
detail
***
when user register on first website a insert query should also make on second website database.
can you tell me how can i write my conenction string:

server1:rs397.secureserver.com (database: abc) , website 1: www.example1.com
server2:rs455.secureserver.com (database: 3214), website 2: www.example2.com

waiting for any one urgent reply
vr4indian@yahoo.com is my email id or you can also reply on this message

Remote Connection To Mysql Database Using JDBC?
I am trying to set up OpenOffice Base to connect to a remote os x server with mysql on it.

It has the default mySQL JDBC driver class set to com.mysql.jdbc.Driver

It also asks for server URL, should this be the ip address?
Port number? Default is set to 3306.

When I set the class it says that the JDBC driver could not be loaded.

SQL Execution Error # 2013. Response From Database: Lost Connection To MySQL Server
I'm upgrading to v4.1 from v3.2 on a Windows XP box; I did an uninstall on the previous version, but Windows services did not remove it as a service (v4.1 was logged as a new service, MySQL4).

I breezed through the install process, but I get an error when I try to launch the .exe file from the command line.  It says ... "ERROR 2013 (HY000): Lost connection to MySQL server during query."  MySQL4 is now an automatically started service under Windows and mysqld-nt is operating in the Task Manager as a process.

When I try to connect via MySQLFront, I get the following error message: "SQL execution error # 2013.  Response from database:  Lost connection to MySQL server during query."

Insert Into Select - Connection Lost
my problem - want to write a query - find new records in one table and insert in an ohter to generate new keys... See below the statement - but wenn I execute the select part it works fine - as soon as I add the insert into for the select i loose the connection to the mysql server (Error 2013)

Connection Do Database Using Psp
I use a hosting company for my websites. I have created a mysql dabase using my hosting company's control panel. Now, I am trying to figure how I connect to it to enter data.

Connection To Database
is the syntax the same as connecting to mssql using asp?? this is how i connect to mssql using asp:

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = SErver.CreateObject("ADODB.Recordset")
strConn = "DSN=FYP_Actual;Driver={SQL SERVER}; UID=sa;pwd=;"
Conn.Open strConn

is this the same way i connect to mySQL too?

Database Connection
I have setup a mySQL database for a PHP nuke forum.

The PHP seems to be able to read ok from the sql but not write. For example the page loads fine but creating a user or changing the layout doesnt work.

I am connecting using the root user so i would have thought all the permitions were correct but i have still checked everything i can.

I have looked at the windows permitions and the IIS permitions and everything is set correctly so far as i can tell.

Connection Database Problems
I'm having currently a problem when trying to connect to a database

First of all I have MySQL server installed in a remote server. When I connect to the DB from my Home using MySQL Administrator GUI Interface I connect fine without any problems. My problem comes in my ASP pages. I'm trying to make a connection with a db in mysql and I can't for some reason. Everything is fine (The RemoteAddress Port Number, UserName, Pwd, etc). If I run the exact same ASP file from the server where MySQL server is installed it works fine, the problem is when I run the ASP file in my PC from my home.

How Often Should Database Connection Be Closed?
I have a question regarding the frequent closing of database connection.

Will it be okay to leave the connection open, once the program starts running till it is closed after the application is quited? Or there should be frequent openings and closings of the database for each query?

Database Connection Failure!
I have uploaded the file to my server and edited the config file to reflect the database I created but when I attempt to access the file I receive the following error: "Database connection failure!".

I have done everything to get this basically simple script to run and I can't find out what the error is, including deleting the database, user, etc. Can anyone please point me in the right direction?

Remote Connection To Database
i have a web-hosted website and i need it to connect to my mysql database is there anyway i could set this up.

Database Connection Fails
I've been having problems with my CGI script, it overloads the
server. I think it's because the database connection fails because
the following error is logged whenever the server overloads.

DBI->connect(server=localhost;database=Employee) failed: at db.pm
line 53
db.cgi:: Could not connect to database
db.cgi:: No database connection exists
db.cgi:: No database connection exists

And I use these settings to run mysqld.

/usr/libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr
--datadir=/var/lib/mysql --user=mysql
--pid-file=/var/run/mysqld/mysqld.pid --skip-locking

I read some documentation that skip-external-locking should be used
instead of skip-locking, but that seems like a minor thing. I'm not
entirely sure it is the database connections, I'm just trying to
eliminate possible causes.

ASP And Database Connection Question
I got the database open with the following code (which all works perfectly)....

// Build the sql statement
m_strSQL = "select * from <datatable> where Remote_IP Like '%" & Request.ServerVariables("REMOTE_ADDR") & "%';"
// Create the MySQL Connection.
set MySQLConn = server.createobject("adodb.connection")
// Open the Database
MySQLConn.open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=<IP Address>;DATABASE=(Database Name>;USER=<User Name>;PASSWORD=<Password>;OPTION=3;"
// Open recordset
Set objRS = MySQLConn.Execute(m_strSQL)
//
If objRS.EOF Then Response.Redirect("ID_Survey.asp")
//
%>

Silly question is, having directed the browser to another page, (or stayed on this one depending on the "objRS.EOF" result) how do I close the Database and Connection?

Connection To Database Failed
Keep getting the error message when trying to connect to a MySQL database:

"Connection to Database failed
Host 'MYSERVER' is not allowed to connect to this MySQL server"

I can sucessfully create and view the database, I can sucessfully login to the MySQL Command Line Monitor AND the MySQL Administrator using the 'root' user so I know my password is good. I have given the IUSR_MYSERVER Internet Guest Account read, write & modinfy privelages to the database folders.

Database Connection Issues
ok here is the problem code
Code:

$db = mysql_connect("localhost", "grav1com_z3r0gr4", "****") or die("Could not connect.");
if(!$db)
die("no db");
if(!mysql_select_db("grav1com_bloghost",$db))
die("No database selected.");

ok when i try to use this script to connect to the database i get no databse selected which is infering that there is no database info in the mysql_select_db variable correct? then what is going on here? is there a slight error that i'm not seeing?

Database Server Connection
I am trying to using mysql as back-end for an application(web) running
on the window 2X, one thing I am not sure is that once I establish the
connection between database server and application, should I keep this
connection open while application is running, or only open it when
there is a requet to qury records from database?

Php/Mysql Multiple Database Select
I'm trying to SELECT from two Mysql Databases in one SELECT statement. Both databases are on the same server. I think I have the SELECT statement syntax correct. What I don't get, is how to connect to query multiple databases at once. I've been messing with the following:

$db1 = @mysql_connect("localhost","db1","password");
$db2 = @mysql_connect("localhost","db2","password");

mysql_select_db("db1",$db1);
mysql_select_db("db2",$db2);

$query = "SELECT db1.field1, db2.field1 FROM db1.table1, db2.table1;
$post_table = mysql_query($query);
I don't have a strong understand of database connections,

Error Establishing A Database Connection
I'm trying to use MySQL on my computer to design and test a WordPress blog locally, but I keep getting the message, "Error establishing a database connection." This isn't limited to WordPress; if I run a simple MySQL test script I get the same problem.

I'm using MySQL 4.0.21 (I installed this old version after getting the same results with a couple of newer versions, so I don't think this is the problem). I'm on OS X 10.4.8.

Using MySQL Administrator, I'm able to connect to the server as root. I created my wordpress schema and assigned all available connection privileges to root on localhost, [computername].local, and %.

I'm used to creating a database and assigning a user to it using cPanel. I suspect the solution is simple and I'm overlooking something obvious because of my newbie status when it comes to MySQL.


Switching Assigned Database For An Established Connection
I am implementing a connection pool using the C API. In my pool, The first time a connection is made, I call mysql_init(&myConn), and then use this myConn connection structure to call mysql_real_connect() with the appropriate user name, password, and a database name to connect to. Once the connection is established, it is used for the current database query and then put back into the pool.

My question is regarding using multiple databases with a single connection pool. If I pop an established connection off the pool and the database it is currently assigned to does not match the requested database of the new query, what do I do?

Do I close the existing connection and create another with the new database name? If so, wouldn't this defeat the purpose of having sustained connections?

What I first tried was to simply call mysql_real_connect() again with the new database name. This worked, but using MySQLAdministrator to look at the list of open connections/threads, I see the original connection was not closed, and I no longer have a handle to it, so it is lost.

Here is some pseudo code:

Intermittently Losing Database Connection During Query
I am using mysql version 4 and java clients written as a windows desktop application using ConnectorJ. The server hardware is a Windows XP machine with service pack 2 running as a virtual server on a windows platform. There are a maximum of 10 concurrent users from the client XP platforms and versions of my program have run pretty well for a couple of years in a similar configuration.

On my current project the charts and reports that I produce keep crashing due to losing connection to the mysql server.

I use auto reconnect and have upped the number of tcp/ip connections on both the virtual server and the client pc. This seems to have helped but problems still arise.

What kind of issues can create this kind of problem? and what are the possible solutions?

MySql: Select Database And Perform Mysql Dump
I currently have a batch file created using shell which runs mysqldump and saves the information to a file. However, I was wondering if there would be a way to use a recordset instead to select the database and initiate the mysql dump.

Ideally this is what i would like to have:
rs.Open "Use database mysqldump  > C:", conn, 3, 3

Does anyone know if this is possible?

Cannot Select Database: No Database Selected
This is the error I get in multiple locations on my website. I am using postnuke for my website. I get this error when I try to access my PostCalendar, PNaddressbook, the modules area in the admin screen, the permissions area in the admin screen, and the blocks area in my admin screen. I had a backup of the entire postnuke folder when it was working. I replaced it with the functional postnuke backup and the problem still exists. I know it isn't Postnuke. The only possible problem could be in MySQL.

Changes Made In One Connection Does Not Reveal In Another Connection At Once.
I use many connection and the same as many threads in my server app to gain performance on a multicpu machine.

Firstlly i call "set autocommit=0" and wrap every statements with "start transaction " and "commit". i use mysql_stmt_execute for every statement rather than mysql_real_execute except those that can't be prepared. The version of mysql is 4.1.11 under Debian linux.

In one connection of one THREAD i insert a row into a table. After i got the sucess code and the last insert id, i then do a "select" from another connection in another THREAD with the "last insert id" return by the previous insert . I expect the select can fetch the row that i have just insert , but some time it does and some time it doesn't.

is there any funtion like "mysql_....flush...cache.." to make the changes from one connection to be reveal to the global at once?

Can't Select Database
I downloaded a user login system off of a PHP site. I am having a lot of trouble with it.

Here is the chunk of code giving the error:

$sql_email_check = mysql_query("SELECT email_address FROM users
WHERE email_address='$email_address'");
$sql_username_check = mysql_query("SELECT username FROM users
WHERE username='$username'");

$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);

I have created the users stuff in my database, but I get this error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/register.php on line 64

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/register.php on line 65
No Database Selected

What could the problem be? I am pretty sure I created everything right (I used phpmyadmin to add the tables under users).

Can't Select Database
I am trying to do a simple mysqldump and when I supply the credentials to connect to the mysql server, I connect fine but when I try to 'use dbname' to select the database, I get a permission denied error and the username that I connected to mysql with is followed by an @%

Select All Tables From A Database
I want to see all the tables from a database which select statement will provide this information.

Unable To Select The Database
I can connect to the database via batch. But when I run the program ivia the internet it does not connect.. I log onto mysql and drop the table and then try it via the internet. It dies. I am using apache 2. I am using Mysql 5.0 and php 4.3.2. My O/S is ES Linux 3.0 update 4. I run Moodle on the same bax that uses Apache and PHP without a problem. What am I missing?

Here is the prog:

$linkID = @mysql_connect(localhost,"browser","mypasswd");

@mysql_select_db($database) or die( "Unable to select database");

Code:

Multiple Database Select
How do I at the best way perform select statements over multiple
databases?

I have a couple of databases containing the same table definitions with
diffrent data. Now I want them to act as a single database giving me
one answer on a select statement but the answer fetched from all my
defined databases.

Right now the databases are on the same node and I guess it is possible
to do something like:

select * from db1.table1, db2.table1 etc etc. but I really do not want
to modify all my sql statements if another database would comes into
picture or is revoved from the set.

MySQL Error 2013: Lost Connection To MySQL Server During Query
I'm running sugarcrm on mysql and the following query is returning "MySQL error 2013: Lost connection to MySQL server during query":

MYsql Connection/PHP
I am getting the following message, when I installed mysql client version 5.1.11. I get this message when I tried to connect through PHP. I am using, windows XP professional.

"Client does not support authentication protocol requested by server; consider upgrading MySQL client"

Connection To MySQL Using .net
I am trying to connect to a MySQL database, using the .Net framework.

I installed the newest MyODCB (3.51) and the .Net ODBC drivers from
Microsoft.

I made a System DSN using the driver, and i get it to connect - so far
so good.

But if i try making a new connection i my code using the sample
connectionstring from MySQL, i get an Exception :(

"An OLE DB Provider was not specified in the ConnectionString. An
example would be, 'Provider=SQLOLEDB;'."

What i try is:

Return New OleDb.OleDbCommand("DRIVER={MySQL ODBC 3.51
Driver};SERVER=localhost;DATABASE=bigshop;UID=root ;PASSWORD=;OPTION=3;")

PHP Connection To MySQL
I'm working on a simple script to create two tables within a database, and I'm sure its just some stupid error I'm making, but I cannot seem to get it to work! Here's my function: Code:

MySQL-PHP Connection
the problem i'm facing is of mySQL-PHP connection. i'm trying ...

<?
$link = mysql_connect("localhost",'root','nawal')or die("Connect Error: ".mysql_error());
print "Successfully connected.
";
mysql_close($link);
?>

and getting this message...

Warning: mysql_connect(): Client does not support authentication protocol requested by server; consider upgrading MySQL client in C:Program FilesApache GroupApache2htdocs estindex.php on line 5

Connect Error: Client does not support authentication protocol requested by server; consider upgrading MySQL client.

MySQL Connection Over LAN.
I have installed mySQL server on a computer (ServerName: AHMED, ip:192.162.0.1) and teh server listens at port:3306.

I type "mysql -u root -p" on command line to connect to the server on local host.

Now I want to connect to the same server over the network from a computer (ComputerName: FARAZ, ip: 192.168.0.2). I Copied mysql.exe to the client PC (FARAZ) and I typed the line "mysql AHMED -u root -p" on FARAZ (Client PC) but It says that it fails to find any mySQL sever on AHMED.

1] If I only have to copy mysql.exe on the client to access mySQL server over a network.
2] Am I right to type "mysql AHMED -u root -p" on the client to connect to the mySQL server?

MySQL Connection
I just install PHP5 and MySQL5. They all work but I can't connect to MySQL via php connection (mysql_connect). Could you tell me what is the matter?

Connection To MySQL
I have installed MySQL administrator tool on my XP machine and would like to know how and if I can connect to MySQl on Redhad Linux server. What do I have to install on the server to be able to manage it using MySQL Administor gui tool?

Connection To MySQL
I New to Linux PHP apache and MySQL (following the Book, Begining.PHP,
Apache, MySQL Web Development). Got as far as chapter 3 without too many
problems. Well no I'm stuck. I get the following error

Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /usr/local/apache2/test/createmovie.php
on line 4

Database connection error, check your server connection

when then following piece of code is executed

$connect = mysql_connect("localhost", "mysql", "mysql" ) or die
("Database connection error, check your server connection" );

I'm, A bit lost about which file the path is stored.

Has anyone came across this similar problem and found a fix for it?

Vb5 Connection To Mysql
I'm trying to use vb5 to connect to a mysql database. I'm sure that the drivers are installed and the database exists because I tested it using vbscript in an asp page.  With the asp page I am able to connect and query the db, but when I try it with the vb5 application, I can't get it to connect. I get this error:

"Data source name not found and no default driver specified".

This is the vb code I'm using

     Dim ConnectionSTR As String
     Dim conn As ADODB.Connection
     Dim Query As String
     Dim rs As ADODB.Recordset

    Text1.Text = "connecting to database..."
    Set conn = New ADODB.Connection
    conn.ConnectionString = "DRIVER ={MySQL ODBC 3.51 Driver}; SERVER = localhost; DATABASE = testunits; UID=root; PWD=; OPTION=3"
    conn.Open
     Text1.Text = "connection succeeded"

Can anyone tell me why this won't work in vb5, but works with vbscript asp?

Mysql Connection
i am trying to connect the odbc connector to mysql i am new to this, i have fields

datasource name
discription
server
user
password
database

i have tried localhost as the server, there is no username or password and the database dropdown box is empty just dont know how to connect?

PHP MYSQL Connection
I got a small problem with mysql php connection i try the following php code but nothing happens other than just showing the first echo "i am here".

Is there something wrong with the code below or am i supposed to make some special settings to connect PHP with MYSQL locally?

<?php
echo "i am here";
$con = mysql_connect('localhost', 'k1m0', 'passy');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("world", $con); .......

Mysql Connection
I am using iPowerWeb to host PHP files and I am accesing their MySql database.

This is what i use to connect to the database:
mysql_connect("localhost", "studentm_test1", "test1");
mysql_select_db("studentm_test");

Just creating this connection can sometimes take up to 45 seconds. The time ranges from .0006 seconds to up to 45 seconds and it gets realy annoying because the connection times are really random. Most of the times it takes around 5 seconds and this is with very few concurrent users. Maybe 3.

MySQL SSL Connection
We have a server which runs mysql and Apache. Our scripts obviously connect to the the database server through "localhost".

Now our server when entering secure areas encrypts all data between browser and server using SSL. Does this mean that the data being extracted from the DB is secure? The DB Server is on the same machine doing the encrypting.

I understand that if the script was making a request to a server on another network/domain or even within a private LAN should be encrpted using SSL.

And I understand that running a mysql server on the same machine as Apache is not the most desirable setup, but just wanted to ensure that the server will be encrypting all of the data.

MySQL Connection
I have a MySQL connection problem.
(using MacOSX/Apache platform)
When I access mysql from the shell, I have no problems.

However, when I try to connect from Dreamweaver MX or MySQL Administrator, I get the following:

"2002 can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

I actually installed MySQL from the website and now have the MySQL preference pane. Restarting the computer or the server from the prefs pane does nothing.

Did I make a mistake by installing MySQL and Apache 2, not realizing that (at the time, I'm dumb) MacOSX came with MySQL and Apache 1.3?

It's causing Apache connection problems as well. When I start Apache 2 server from the prefs pane (if web sharing is turned on) it says : "you already have an instance of Apache server running". If I turn off web sharing from the prefs panel, I can then start the Apache server from the Apache prefs pane; however, i can no longer connect to my localhost and I can no longe turn on web sharing.

My questions are:

1)Do I need to uninstall Apache 2 server, or is there a way to reconfig so that I can run it from the prefs pane?
2)Did I make a mistake by installing MySQL and MySQL Admin?

MySQL Connection Through LAN
We are new to using MySQL and ran accross a very simple issues. I have installed MySQL in one of the widows XP machine and now i want my network users to access that MySQL database. We are unable to connect. All pcs are in a common work group but still none of the pc's is able to access the MYSQL database from LAN.

Is there any special configuration needed for the my sql server to be able to access it through LAN? Please help ASAP.

Note:- All pcs in our network are running windows XP (including the one in which we have installed my sql to use as a my sql server).

MySQL Connection
Trying To Setup paFileDB, Yes I Have Everything Uploaded, Im Trying To Install it.. http://ultimatemedia.freehostia.com/DLDB/install and im am getting a connection error..

Error: paFileDB Error
paFIleDB encountered an error while running a database query and is unable to continue.

For technical assistance, please visit The PHP Arena support page.
mysql error: [1045: Access denied for user 'joecha10_chat'@'hex12.freehostia.com' (using password: YES)] in CONNECT(mysql3.freehostia.com, '****', '****', joecha10_chat)

MYSQL Connection
If I link to a page after connecting to a database, and the user follows the link, the connection is lost. Is there any way to transfer the connection to the next page

MySQL Connection
Will any body tell how to connect MySQL using My ODBC 3.51 through ADSL modem and router. I have ping the IP of the server successful but using MySQL query connection to same IP fail


Copyright © 2005-08 www.BigResource.com, All rights reserved