Php Error Cannot Select Database
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up PHP and MySQL - can't select database up vote -1 down vote favorite I'm trying to use a database 'coolometer. I've tried connecting like this: $con = mysqli_connect("localhost", "x", "x", "coolometer") or die("cannot connect"); But it just says 'no database selected'. Any suggestions? php mysql share|improve this question asked Mar 21 '13 at 6:48 Tiffany 1211416 1 if mysqli fails it should output cannot connect. check in which line the error occur. –Yogesh Suthar Mar 21 '13 at 6:50 1 Can you show us the condition in which you have show the message 'no database selected ? –Rikesh Mar 21 '13 at 6:50 1 It's not a condition I've written, I think it must be a built-in error? I can't find it in my code! –Tiffany Mar 21 '13 at 6:55 add a comment| 4 Answers 4 active oldest votes up vote 2 down vote accepted i think your MySQLi extension is disabled, so you need to first check var_dump(function_exists('mysqli_connect')); if it outputs bool(false), then you need to enable MySQLi extension. share|improve this answer answered Mar 21 '13 at 6:59 Prashant Shukla 174112 I changed everything from mysqli_query to mysql_query and it worked. –Tiffany Mar 21 '13 at 7:10 add a comment| up vote 1 down vote Check if your database name is correct, sometimes, there is a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up php mysql query connection error cannot select database up vote 1 down vote favorite I'm having http://stackoverflow.com/questions/15541141/php-and-mysql-cant-select-database some trouble making a connection to my database. As far as I'm concerned I'm using the same code as usual. But suddenly I can't seem to make a connection. I've tried the script locally using MAMP aswell as online on my server. I use a config file to select and connect the database with the following code: http://stackoverflow.com/questions/13722026/php-mysql-query-connection-error-cannot-select-database mysqli_connect($db_host,$db_username,$db_password) or die("Cannot connect"); mysqli_select_db($link, $db_database) or die("Cannot select database"); ?> Next I try to print info from my database on my page using the following code:
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols http://php.net/manual/en/function.mysql-select-db.php and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting Using Register https://www.sitepoint.com/community/t/cannot-select-db-using-mssql/68902 Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote php error files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human php error cannot Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box mysql_set_charset » « mysql_result PHP Manual Function Reference Database Extensions Vendor Specific Database Extensions MySQL MySQL (Original) MySQL Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug mysql_select_db (PHP 4, PHP 5)mysql_select_db — Select a MySQL database Warning This extension was deprecated in PHP 5.5.0, and it wa
connect to my database.I used the following:php 5.1.4 IIS 6.0Microsoft SQL Server 2005 Express EditionSQL Server Management Studio Express Here is my code: "dbtest"); //Because UID and PWD are not specified in the connection option, the connection is made with Windows Authentication. $conn = mssql_connect($server) or die("Could not connect"); $selected = mssql_select_db($connectOptions)or die("Cannot select DB"); $department = $_POST['department']; $username = $_POST['username']; $sql=mssql_query("SELECT `Department`, `Username` FROM `tbluser` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mssql_min_error_severity()); $ct = mssql_num_rows($sql); if($ct == 1) { // im guessing this means that the user is valid. $_SESSION['loggedin'] = true; // now that the user is valid we change the session value. $row = mssql_fetch_assoc($sql); //$_SESSION['username'] = $row['Username'] ; //$_SESSION['department'] = $row['Department']; $Departments=array('aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh', 'ii', 'jj'); if (in_array($row['Department'], $Departments)){ header ('Location:company.php'); }else{ echo "Incorrect Username or Department"; header ('Location:index.php'); } } ?> And when I run this code the result is: Cannot select DB Thank you in advance rhodarose 2010-10-13 08:09:13 UTC #2 r937 said: can't help you with the php code, but i noticed you are using backticks in the actual sql that works in mysql, but it's gonna fail in mssql I try a new code: $db = "dbtest"; $selected = mssql_select_db($db) or die('MSSQL error' . mssql_get_last_message()); and the output is:MSSQL error.The several principal "[domain name]\IUSR_[computer name]" is not able to access the databse "database name" under the current security context. Then I research about this error and I find a step to fix the error, but I can't follow the steps because I can't find what they say in the