3

PHP - Selection of the currently used database

 3 years ago
source link: https://www.codesd.com/item/php-selection-of-the-currently-used-database.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PHP - Selection of the currently used database

advertisements

I am having a problem in getting the string name of the currently selected database. this is what i did.. i am trying to echo the name of the database but it produces an error "Warning: mysql_fetch_array() expects parameter 1 to be resource"

<?php
$dbcon = mysql_connect("localhost", "root", "")
        or die(mysql_error()."Not Connected");

$sql = mysql_query("select database()");
$row = mysql_fetch_array($sql);
echo "db ".$row[0];

?>

i need to get the selected database name because i will use it for

mysql_select_db()


You should either select a database right after connecting using your login credentials. Or, if you want to see what databases the root user has access to, use:

SHOW DATABASES;

Related Articles

JQuery select only the current item when using on the click

Is it possible to cleanly select only the current clicked div and not children when using .on("click",? Basically I have a outer div that when faded in is 100% width and 100% height, it then has a container in the middle, my aim is to have it wh

Is it possible to use vimgrep for a visual selection of the current file?

I would like to search with vimgrep only within a visual selection of the current file and not the whole file. Is that possible and how? I couldn't find something for this case with Google or in vim help. The reason why I want this is because I need

PHP: What are the column-oriented databases

What are the currently used Column Based Databases that work with PHP? and are any of them free?I think you want to know about NoSQL databases and not Column Oriented DBs. Both are often called as the NoSQL databases, most of the implementations are

Change the current MongoMapper database at run time

How to change the current MongoMapper database at runtime? Also, is there a way of mapping a model to a database whose name is dynamically calculated? For instance: class MyEntity include MongoMapper::Document set_database_name "#{some_dynamic_value}

PayPal WPP requires PHP cURL library. (Current use of CURL Not Found)

On the Ubercart module, whenever I enable PayPal it gives me this error: PayPal WPP requires the PHP cURL library. (Currently using cURL Not found) I have no idea... Can some one please tell me how to handle this problem... Note: OS-windows 7, Drupal

How to get the size of the current sqlite database or the size of the package in Android?

I can't get the total amount of data used by an Android Application (or package), because the official API support has been deleted: http://groups.google.com/group/android-developers/browse_thread/thread/df94daae34336aad/f96a8425549c6637 (is this sti

How do I replace the current MySQL database with an .sql file?

I'm trying to restore the current working database to the data stored in a .sql file from within Django. Whats the best way to do this? Does django have an good way to do this or do I need to grab the connection string from the settings.py file and s

PHP Drop-down list of all records in the database + selection of the current record

I have a PHP dropdown of a list of groupnames (together with id, so it can be updated). In this FORM page you can change the groupname specified for an item by choosing possibilities from the dropdown coming out from the database. My code below works

How to make the selection of the current page use navigation

I am using php includes to limit redundancy on my pages, how can I have my navigation have the current page selected with say a certain color for the HOME button when my navigation is called from a header.php file. If i were to say to add a "active&q

Is there a way to get ONLY the PHP page of the current page using javascript?

I want to get the my exact location (only PHP page) using javascript, I'm currently using window.location to get the exact url for example: localhost/empc/myfolder/functions.php what is the code if I want to get only functions.php as a result? Is it

MySQLI Select from the table using prepared statements

I am currently in the process of changing all my old MySQL to MySQLI. However, I'm having a problem when trying to SELECT from a table when using prepared statements. Tags is a string. My test URL is: http://example.com/retreiveCustomArticle.php?Tags

How to start the php calendar on the current month of the viewer

im trying to set up the calendar from http://davidwalsh.name/php-calendar-controls. hes provided some great code and on paper it seems to be perfect for what i need. but im a little rusty with my php and im getting some errors. its kind of an old blo

PHP Check if the current time is before the specified time

I need to check in PHP if the current time is before 2pm that day. I've done this with strtotime on dates before, however this time it's with a time only, so obviously at 0.00 each day the time will reset, and the boolean will reset from false to tru

JQuery How to select only the current and non-parent li

How do you select using JQuery the current li and not its parents. In my sample below, when I hover over a li that has a parent li the 'world' gets displayed on the parent as well as the current li. I would like to only display the 'world' in the cur

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK