I am new to WebMatrix and MySQL, and I need some assistance with an issue.
I'm trying to code with PHP and MySQL in WebMatrix 3. I am experimenting with scripts in a site file called "Starter PHP site". WebMatrix is not showing a database created with the $sql="CREATE DATABASE my_db"; script when I navigate to the "Databases" section in the program. This image shows what part of the program I'm talking about.
(source: orchardproject.net)
When I click the "Databases" button in the lower left corner of the UI, all that is shown in the left pane is a "Starter PHP site" folder icon (for creating a MySQL databse for my site from the WebMatrix UI) and an "Other Connections" icon -- but not the database created (my_db) after running the script above.
I know that the database exists...because when I run the script above again with some extras--
$con=mysqli_connect("localhost","xxxx","xxxxxxxx");
$sql="CREATE DATABASE my_db";
if (mysqli_query($con,$sql))
{
echo "Database my_db created successfully";
}
else
{
echo "Error creating database: " . mysqli_error($con);
}
--I get an error saying that "my_db" already exists. Why doesn't WebMatrix show my_db in the "Databases" section...after I've run the script to create the database?
What am I missing here?
Any advice is greatly appreciated.
If it's there you should see it as such:
Dumb question, but have you tried refreshing?
It seems that I have found some sort of solution. Apparently, WebMatrix 3 might not show MySQL databases created with PHP scripts automatically, but you can view databases created with scripts by creating a new MySQL database connection to the database of interest from the WebMatrix GUI.
Solution: Navigate to the "Databases" section.... Select "New," then..."MySQL Connection." Then, enter the database information.... You should now have a working database connection.
...sorry if this is one of those newbie mistakes. I should have tried this earlier, but one might think that, since one has to establish a database connection in the PHP code, WebMatrix would automatically connect to it. For me, that isn't the case.
Related
I am using PHPMyAdmin 4.2.11 and Drupal 7.37
I created a database in PHPMyAdmin called drupaldatabase and now I'm trying to add it on Drupal using database name: drupaldatabase and username root with no password.
If you need any more info let me know.
You should make sure your database is empty by killing it
mysql> DROP DATABASE drupaldatabase;
And create database again:
mysql> CREATE DATABASE drupaldatabase;
MySQL configuration:
autocommit = on
I'm trying to install a php script locally on IIS.
I've gotten to the point where I need to fill in my database information.
I've connected to another database through visual studio, here's the connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\TaskSubmitter.mdf;Initial Catalog=TaskSubmitter;Integrated Security=False; User Id=sa; Password=thepassword"
Now I've created a database named "pligg" for the php script.
The information I've filled in is the following:
Database name: pligg
Database username: sa
Database password: thepassword
Database server: (LocalDb)\v11.0
Table prefix: _pligg
However I get an error when trying to connect through the script.
The script is working fine so I'm sure I've done something wrong regarding the settings or the database.
Anyone know what could be wrong?
I have Access 2007 installed and I downloaded the Northwind Traders sample database which is easily available on the Internet.
I want to open connection with this database in PHP so that I can practice my PHP coding. I want to directly access the database without having to export it to MySQL and then accessing it.
I followed the following steps from http://www.w3schools.com/php/php_db_odbc.asp to achive that:
Open the Administrative Tools icon in your Control Panel.
Double-click on the Data Sources (ODBC) icon inside.
Choose the System DSN tab.
Click on Add in the System DSN tab.
Select the Microsoft Access Driver. Click Finish.
In the next screen, click Select to locate the database.
Give the database a Data Source Name (DSN).
Click OK.
Then I tried the following code in php :
<?php
$conn=odbc_connect('northwind','','');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
?>
But it is displaying "Connection Failed".
Please advise me how I can connect to Northwind database directly.
When I launch the website through local host, I get the following error:
Database Error: Unknown database 'db_name'
I'm having a dig around as to what the problem is. The website belongs to a friend of mine and he wants me to connect the website to the database. The database resides within the root directory. I'm merely trying to connect to it.
In most of the PHP files, there is a tag that includes the config file which contains the details of the database.
Any ideas as to how I can get it working and resolve the Database Error: Unknown database 'db_name' error?
Any help is highly appreciated.
Database should not reside in root directory, it should be imported to database (Mysql) server.
Check in Mysql databases, does your database resides there?
If not, you can do so by phpMyAdmin or navigating to your mysql and importing it.
Create database in mysql and import the sql file as below by opening command-line terminal:
/path/to/mysql/bin > mysql -u username -p < /path/to/root/db.sql
I'm working on a WordPress theme that requires a db in mysql to store lots of data.
I'm currently working on an installation script to install the theme. I have written a function to create a new db in the same mysql that WordPress uses it self.
Every time i run the script, i get redirected to a page stating that WordPress is already installed. But I'm not trying to reinstall WordPress, just create a new db in the same sql that WordPress uses.
I have also written a function to create new tables, which works fine so I'm sure there is no issues with connection.
If this helps, here is the function:
function create_db_mysql(){
require ('con_db_var/db_4216841335655434.php');
$connect = mysql_connect($db_host,$db_user,$db_pswrd) or die(mysql_error());
mysql_query("CREATE DATABASE theme_db",$connect);
mysql_close($connect);
}
I fetch the db info from wp-config.php.
so in the db_4216841335655434.php:
require ('../../../wp-config.php');
$db_host = ( DB_HOST );
//etc etc....
when i call the create_db_mysql(), I get taken to a page telling me that WordPress is already installed and then followed by instructions on how to re-install.
any ideas?
thanks!
Database creation and table creation are different levels of privileges. Many shared hosting providers will not give PHP the access to create a database.
So you might need to use your hosting providers control panels to create the database.