top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to select a mysql database in php?

–1 vote
How to select a mysql database in php?
posted Mar 13, 2017 by Kavyashree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Using mysql_select_db() function we can select a database in PHP is mysql is in connected state. Following sample code may help you -

$db=mysql_pconnect(<hostname>, <username>, <password>);
if (is_resource($db)) {
   if (!mysql_select_db(<database>, $db)) {
          // <report error>;
// Now we can use $db in various operation
answer Mar 14, 2017 by Arun Angadi
Similar Questions
0 votes

I have a client where their next auto-increment number just jumped from 2300 to ********** for reasons not understood. They want it set back.

Options such as dropping the primary key and rebuilding the index is NOT possible -- this is a relational table thing. So, is there a way (programmatically) to set the next number in an auto-increment?

Something like:

alter table abc auto_increment = 2301;

Any ideas of why this happened?