I have successfully setup a localhost (Individual Installs) with Apache 2.2, MySQL and PHP, as well as setup a couple virtual-hosts. Currently, I am trying to teach myself command line in MySQL. The part I am lost on is setting up the connection between the database that I create and the virtual-host website I am working on. In my mind I would want to save the database for a specific website in the same folder that I am creating the website. However, I could be way off base. Could some body explain how this piece of the puzzle and how it works. I tried to Google it and all I get is information regarding Work Bench and phpMyAdmin.
The MySQL server runs as a service (or daemon) on your server - so the folder (or directory) you put it in is set by the system configuration and has nothing to do with your document root for your web site.
In PHP, you will "connect" to the MySQL service using PDO or something similar and then send requests to the MySQL server using PHP commands.
When you are running the MySQL command line interpreter, you can also test those same commands by typing them yourself. This is helpful when you're debugging your PHP program so you can see the data that your program will get yourself in the command line interface.
I hope this helps put you in the right picture.
I tried to Google it and all I get is information regarding Work Bench and myPhpAdmin
this is the first entry on the first page when I google php mysql, it covers everything from installation up to code example.
Very generally:
You need to check with your hosting company if they offer you locally hosted MySQL server access. Using cpanel/phpMyAdmin, or whatever tools they have available for you, you can then login and create multiple databases as you please - each database maybe corresponding to one of your site folders. Once you have created your account and your databases, you can use php commands from your website code to connect to/manipulate whichever database you want.
EDIT: I missed where you said you already have a MySQL localhost setup. Now you need to login to your SQL server and create one or more databases and one or more user accounts for those databases. Create an admin account with all the privileges. Then you can use php in your webpage to connect to a database, using something like this:
$con = mysql_connect("localhost", "your_MySQL_username", "your_MySQL_password") or die ("Unable to connect to MySQL Server " . mysql_error());
if(is_resource($con))
$db = mysql_select_db($MySQL_database, $con) or die( "Unable to select database " . mysql_error());
See the manual for more ways to query the database and handle the results: http://php.net/manual/en/ref.mysql.php
Related
I have access to a remote Oracle database when using Toad or SQL Developer.
The connection is specified by a TNS record and user+password of course.
Now I wish to have a local webpage that shows (regularly refreshed) data from the database. At first I was thinking of using php but I guess that can only be used on the server itself and I am unable to create files on the server. Of course a server page would be more suitable when there's multiple users but here there's only one.
In fact I just want to do the same as is done by running queries from the tools mentioned, but now called from a custom webpage. I feel this should be possible because the tool has to establish the connection from client to server db also; but I don't know how to set up my local client webpage(s).
Is this possible by applying php or javascript if that's more suitable?
Well you have to understand that the functionality of connecting to oracle database is packaged as part of frameworks, there are no such frameworks in javascript which can help you.
you are right with php, however it needs a webserver to run and they are free :)
the reason why php can connect to oracle database is, it has the framework to do those operations.
for now the answer is no.
or you can see if you can write an Activex which can connect to Oracle database and refresh, microsoft provides framework / api to connect to databases
The best way to do that kind of thing is AJAX: a javascript code calls a PHP page on the web server, this page connects to the DB and returns data to the javascript that updates the page.
I have to code an application on my server that triggers emails based on info that come from a database hosted on another server and I don't know how to query that information. I'm using PHP/MySQL. I can't established a connection to this database like I do normally (when database is host on the same server that the application file), right?
Thanks in advance,
Wrong, there is no difference whether code and database are on the same or different servers. As long as the remote db server is configured to allow conections from foreign hosts that is... But that's a hosting issue not a programming one.
I'm not really sure why you wouldn't be able to. I've hosted databases on servers other than my hosting server before.
Try this
$my_db = mysql_connect('yourdb.com:3307', 'myuser', 'mypassword');
if (!$my_db) die('This might be a problem: ' . mysql_error());
If mysql is on another machine , from mysql, you have to give permission for outsider.
is it necessary to use php to connect to the MySQL
i am working the desktop application and do not have a knowledge of php either
is there any in build class or functionality that can be use to connect to the MySQL
although there are many programme present over the internet to do so but unablefind one without the use of php. is there any reference or can i have the step by step example regarding the work.
MySQL config has the default settings. like username is root and password is blank my server name is local host.
No. PHP is a programming language. MySQL is a database. Install MySQL and type mysql from the command line and you will be connecting to MySQL using mysql.
MySQL docs
If you're writing a desktop application, mysql probably isn't the database you want to use. If you want to store data locally, try something like an embedded sqllite database. If you want to store the data remotely, I STRONGLY recommend to put the database behind an API. That is where something like PHP would come into play. It doesn't have to be PHP though. It can be python, java, ruby, etc.
Whatever you do though, DO NOT talk directly to a remote mysql database from your desktop app. That's just asking to have your db hacked.
MySQL has nothing to do with PHP, except that they are often bundled together. If you need to access MySQL by itself you can download MySql workbench.
http://www.mysql.com/products/workbench/
If you need a driver for your language google 'language + MySql Driver'
While I've been working with MySQL for years, this is the first time I've run across this very newbie-esq issue. Due to a client demand, I must host their website files (PHP) on a IIS server that is not running MySQL (instead, they are running MSSQL). However, I have developed the site using a MySQL database which is located on an external host (Rackspace Cloud). Obviously, my mysql_connect function is now bombing because MySQL is not running on localhost.
Question: Is it even possible to hit an external MySQL database if localhost is not running MySQL?
Apologies for the rookie question, and many thanks in advance.
* To clarify, I know how to connect to a remote MySQL server, but it is the fact that my IIS web server is not running ANY form of MySQL (neither server nor client) that is giving me trouble. Put another way, phpinfo() does not return anything about MySQL. *
Yes, you can use a MySQL database that's not on the same machine as Apache+PHP.
Basically, you'll connect from PHP to MySQL via a network connection -- TCP-based, I suppose ; which means :
MySQL must be configured to listen to, and accept connections on the network interface
Which means configuring MySQL to do that
And given the required privileges to your MySQL user, so he can connect from a remote server
And PHP must be able to connect to the server hosting MySQL.
Note, though, that habing MySQL on a server that's far away might not be great for performances : each SQL query will have to go through the network, and this could take some time...
If phpinfo is not returning anything about MySQL you need to install the MySQL plugin for PHP, easiest way to do that probably is to just upgrade PHP to the latest version. If not there is a .DLL file that you will need.
http://www.php.net/manual/en/mysql.installation.php
you will need to install the mysql extensions. this link should help: http://php.net/manual/en/install.windows.extensions.php
The MySQL server has nothing to do with PHP itself. What "mysql support" in PHP means is that it's been compiled with (or has a module loaded) that implements the MySQL client interface. For windows, it'd be 'mysql.dll', and on Unix-ish systems it'd be 'mysql.so'. Once those are loaded, then the various MySQL intefaces (mysql_xxx(), mysqli_xxx(), PDO, MDB2, etc...) will be able to access any MySQL server anywhere, as long as you have the proper connection string.
had a bit of confusion going around in work earlier. Thought id run it by yous to see if anyone knows wats going on.
Were working on an internal administration system for our client, and its rite about to launch. Its comprised of TWO MySQL databases on the server [db_1 and db_2] and a PHP front end. [Both databases contain several tables].
There are maybe 90 different PHP files, some of which require a connection to our databases and ALL of these connections are made via a single PHP function which explicitly connects to the first database mentioned above [db_1] and supplies the login and password. And this works fine.
However, our second database, db_2, does not seem to require its own login and password to access its contents.
As soon as we connect to db_1, we seem to have full access to db_2, as long as we use the Full-Name for our tables [ie: db_2.usersTable] -> ("SELECT * FROM db_2.usersTable WHERE...").
And this is what was causing much confusion.
My question is this: Once you connect to a database on a server, do you have access to other databases on that server, or are we overlooking something???
Any feedback greatly appreciated lads...
You usually don't access a database server by a specific database, but by a user that has access to one or more databases.
for example:
mysql_connect("localhost", "user", "password") or die(mysql_error());
connects to the server and not a specific database.
Once connected to the database server you have access to all databases for which that user has permission. You just need to specify the database name in your queries if there are multiple databases that aren't the default.
mysql_select_db("myTable") or die(mysql_error());
sets myTable as the default, but you can still access other tables that the user has permission to.
I might be wrong, but doesn't PHP only connect and authenticate with the MySQL server with a user? And thus, based on that user's permissions, PHP can select any database that user has access to. I would check the permissions for the user you are connecting with...
Once you connect to a database on a
server, do you have access to other
databases on that server
If you have permissions to other databases, then yes. When you connect, you're connecting to the server and setting your default database to the one specified. Which is why you have to explicitly specify db_2 when you want to access it, but you don't have to specify db_1.