Unsure of how to use database with external php page

CHT

New member
Genesis said:
Looks like the db host value can be: localhost:3306

If 3306 doesn't work try 3307 - check this discussion:
https://stackoverflow.com/questions...nect-to-mysql-at-localhost3306-with-user-root

You can also check the php docs for guidance:
http://php.net/manual/en/function.mysql-connect.php

Also check out mysql docs:

https://dev.mysql.com/doc/refman/5.7/en/adding-users.html

I was trying to access a db from here from an external PHP page instead, sorry for the confusion.
 

Genesis

Administrator
Staff member
@"CHT"

Can you spell out exactly what the problem is, and if you can't due to privacy issues, open a thread in the Private Inquiries Forum.

1. Exactly what are you trying to do? Please spell out the details - i.e. you want to achieve XYZ with XYZ domain. Which server is it on - our server? Which server is the php page on - an external server?
2. How are you trying to do it? Again give us the nitty gritty details. What are the steps you're using - details please.
3. What is the error that comes up when you have failed to do it?
 

CHT

New member
1. I'm trying to use a test environment PHP page, which is externally hosted, with a created database from the hosting here.
2. Since it's PHP, I used the normal stuff I would have as if it's localhost, except replacing the host value which has proven to be unsuccessful so far.
3. Didn't really log down the error, so can't really show it. Sorry about this.
 

ferreira

New member
use php debug mode and gives us more details to help you.
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);

your code.....
?>

or
create a page with the code,
add a control variable to turn on and of the debug mode
and import the file based in the control variable.
 

Genesis

Administrator
Staff member
@CHT It's a good topic, however if you want to create a hosting support thread please let it be for real issues with real factual information. I sense you're searching for how to's. Nothing wrong about this except please don't do this in the hosting support forum. I'm moving this thread to the Programming & Scripting Sub-Forum.

CHT said:
1. I'm trying to use a test environment PHP page, which is externally hosted, with a created database from the hosting here.
2. Since it's PHP, I used the normal stuff I would have as if it's localhost, except replacing the host value which has proven to be unsuccessful so far.
3. Didn't really log down the error, so can't really show it. Sorry about this.
Why not try the following.

In cPanel there is a function called "Remote MySQL". You can use that to give the external server and php page permission to connect to your database. Technically it should work - although I don't know for sure as I don't know whether un4 allows it. Also, not sure whether you need to have a static IP for the php page source to work. Hopefully those who have used this function will join the discussion.

You can check tutorials below:

https://www.codexworld.com/connect-access-remote-mysql-database-cpanel-php/

Together with more details of how to connect the mySQL database columns with the php form:

[video=youtube]

This looks like a good tutorial too:

https://coolestguidesontheplanet.com/how-to-connect-to-a-mysql-database-with-php/

Here's cpanel documentation on the remote server function:

https://documentation.cpanel.net/display/ALD/Remote+MySQL#
 

riddict

New member
I am not so clear with your problems, are you trying mysql remote connection?
If so then @un4saken may have the answer. I myself have successfully connected to my remote sql using navicat but unable to connect using php in a remote server.
 

Genesis

Administrator
Staff member
riddict said:
I myself have successfully connected to my remote sql using navicat but unable to connect using php in a remote server.
That should be an answer in itself then. @un4 doesn't allow it.

Interesting to hear about navicat though. If I may ask, have you tried the remote mySQL tool in cPanel yet? In theory it's supposed to give a remote server access to the database.
 

riddict

New member
Genesis said:
riddict said:
I myself have successfully connected to my remote sql using navicat but unable to connect using php in a remote server.
That should be an answer in itself then. @@un4saken doesn't allow it.

Interesting to hear about navicat though. If I may ask, have you tried the remote mySQL tool in cPanel yet? In theory it's supposed to give a remote server access to the database.

I have this other free shared hosting somewhere with cpanel access. I filled in my ip address in remote mysql so it will listen to it, but it still can't connect. So, I think it will be up to the server administrator whether he allow remote connection or not.
 
When connecting an external PHP page with a database, it's important to use the right PHP extension. The most popular extensions are MySQLi and PDO, but which one is right for your project?

MySQLi is the most common extension used for working with MySQL databases. It's easy to use and has a wide range of features. PDO is another popular option for working with databases. It's a bit more complex than MySQLi, but it's also more flexible.

If you're not sure which extension to use, ask your web host or database administrator for advice. Also you can check this practically on my website SEO Consultancy Services