[PHP] MySQL Connection Error - mysql_select_db
Thanks for all the help so far, great to have others out there helping. Only way it will let me connect is to explicitly use the connection information in the connect statement and the select_db statements, can't pass in the variables. This seems a little on the insecure side, and a pain. Is it supposed to be like this, or is it just something that is wrong on my php implementation? It would just be nice to have the connection information in 1 file, so that if it is updated or changed, it can be modified in one file, instead of all files that need it. Thanks for the help! -Patrick _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL Connection Error - mysql_select_db
I don't think those variables are readable in the function. Not totally sure though. Tyler Longren Captain Jack Communications [EMAIL PROTECTED] www.captainjack.com - Original Message - From: "Patrick Hartnett" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, March 30, 2002 10:02 PM Subject: [PHP] MySQL Connection Error - mysql_select_db > here is a function used to authenticate users against mysql database. > Problem is, I am not connecting for some reason. I have the db variables: > $db_host > $db_user > $db_pass > $db_name > > They are populated from an include ("x.php") in the beginning of the php > section. It is getting past the connect statement, but it is not selecting > the proper database, and gives a: > > "Error in query: No Database Selected" > > in the error trap below (die). Any ideas what is wrong? Am I missing some > syntax, or what? > Thanks. > > Patrick > > ## > > function authenticate($user, $pass) > { > > // check login and password > // connect and execute query > $connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable > to connect!"); > $query = "SELECT id from users WHERE username = '$user' AND password = > PASSWORD('$pass')"; > mysql_select_db($db_name); > //mysql_select_db("devweb"); <--what it should be, from file > $result = mysql_query($query, $connection) or die ("Error in query: " . > mysql_error()); > > // if row exists -> user/pass combination is correct > if (mysql_num_rows($result) == 1) > { > return 1; > } > // user/pass combination is wrong > else > { > return 0; > } > } > > _ > Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL Connection Error - mysql_select_db
31/03/2002 01:02:04, "Patrick Hartnett" <[EMAIL PROTECTED]> wrote: You Need to use the command Mysql_Select_Db("$db_name") Or Die("Unable to connect!"); after connect with mysql I use something like this: mysql_connect($db_host, $db_user, $db_pass) or die ("Unable to connect!"); Mysql_Select_Db("$db_name") Or Die("Unable to connect!"); I don't use a $connection like var. >here is a function used to authenticate users against mysql database. >Problem is, I am not connecting for some reason. I have the db variables: >$db_host >$db_user >$db_pass >$db_name > >They are populated from an include ("x.php") in the beginning of the php >section. It is getting past the connect statement, but it is not selecting >the proper database, and gives a: > >"Error in query: No Database Selected" > >in the error trap below (die). Any ideas what is wrong? Am I missing some >syntax, or what? >Thanks. > >Patrick > >## > >function authenticate($user, $pass) >{ > > // check login and password > // connect and execute query > $connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable >to connect!"); > $query = "SELECT id from users WHERE username = '$user' AND password = >PASSWORD('$pass')"; > mysql_select_db($db_name); > //mysql_select_db("devweb"); <--what it should be, from file > $result = mysql_query($query, $connection) or die ("Error in query: " . >mysql_error()); > > // if row exists -> user/pass combination is correct > if (mysql_num_rows($result) == 1) > { > return 1; > } > // user/pass combination is wrong > else > { > return 0; > } >} > >_ >Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] MySQL Connection Error - mysql_select_db
here is a function used to authenticate users against mysql database. Problem is, I am not connecting for some reason. I have the db variables: $db_host $db_user $db_pass $db_name They are populated from an include ("x.php") in the beginning of the php section. It is getting past the connect statement, but it is not selecting the proper database, and gives a: "Error in query: No Database Selected" in the error trap below (die). Any ideas what is wrong? Am I missing some syntax, or what? Thanks. Patrick ## function authenticate($user, $pass) { // check login and password // connect and execute query $connection = mysql_connect($db_host, $db_user, $db_pass) or die ("Unable to connect!"); $query = "SELECT id from users WHERE username = '$user' AND password = PASSWORD('$pass')"; mysql_select_db($db_name); //mysql_select_db("devweb"); <--what it should be, from file $result = mysql_query($query, $connection) or die ("Error in query: " . mysql_error()); // if row exists -> user/pass combination is correct if (mysql_num_rows($result) == 1) { return 1; } // user/pass combination is wrong else { return 0; } } _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php