I am working on a Joomla website and we are running jomsocial, my question is about the database connection using JFactory. Currently I need information from a database table that is not part of jomsocial so I have to get in the database from a specific page, and I'm doing it wrong. Only because I can't figure out how to make the right way work, so I'm asking here for help. Currently I am just using regular php and mysql_connect.. my DB connection looks like...
$db_host = 'localhost';
$db_user = 'xxxxxxxx';
$db_pass = 'xxxxxxxx';
$db_database = 'xxxxxxxx';
$link = mysql_connect($db_host,$db_user,$db_pass) or die('Not connected');
mysql_select_db($db_database,$link);
$user = CFactory::getUser($userid);
$user_plan = mysql_query("SELECT blah FROM blah WHERE blah = '".$user->id."'");
$user_plan_row = mysql_fetch_array($user_plan);
And this works, even though its wrong. What I want to do is use
JFactory::getDbo();
I have found this page which describes the syntax well I think, but I can not implement any of the methods described without breaking the page...
Any Ideas or help is greatly appreciated, as it stands right now I have all my secure information in the file and I don't want that I want to use the correct method, because when it comes time to move the site I'm going to have to go change each one of these manually instead of just changing the config file like usual.
The resource you linked to seems fine to me , you will need to post some specific errors.
Related
I'm running into an issue while trying to link a MySQL database to a PHP file.
Im trying to setup this PHP login system from Github and currently I'm trying to setup the dbconf.php file. This is the code where I'm trying to link the database to.
<?php
//DATABASE CONNECTION VARIABLES
$host = "localhost"; // Host name
$username = "user"; // Mysql username
$password = "password"; // Mysql password
$db_name = "22445671_login"; // Database name
//DO NOT CHANGE BELOW THIS LINE UNLESS YOU CHANGE THE NAMES OF
THE MEMBERS AND LOGINATTEMPTS TABLES
$tbl_prefix = ""; //***PLANNED FEATURE, LEAVE VALUE BLANK FOR NOW***
Prefix for all database tables
$tbl_members = $tbl_prefix."members";
$tbl_attempts = $tbl_prefix."loginAttempts";
The MySQL Database is named 22445671_login
I am just looking for a way to link the MySQL database to my document
Any help is greatly appreciated, thanks.
As put into my original question before it was removed. My website is hosted at at-space which comes with a PHPmyAdmin account linked to my website, I dont know how to link the MySQL database since I don't know if the username and password are just username and password. And I dont know if the host would be 1. My Website 2. atspace or 3. PHPMyAdmin
Where is your database hosted?
You might need to replace "localhost" with the hostname of your server:
$host = "localhost"; // Host name
Make sure you have the correct username and password
Make sure the user has the necessary permissions
Not sure if PMA has this feature, but SIDU has this feature:
<?php
$url = 'http://example.com/sidu54/conn.php'
.'?conn[host]='. $host
.'&conn[user]='. $username
.'&conn[pass]='. $password
// OR .'&conn[pass]='. $encryped_pass .'&conn[penc]=1'
.'&conn[dbs]='. $db_name
.'&conn[eng]=PDO_mysql'
.'&conn[char]=utf8'
.'&cmd=Connect'
.'&url=db.php'
.'&id=1,'. $db_name;
echo 'Click here to manage database';
I'm thinking about a concept of how can I serve file/video without exposing the real path/url. What I have in mind is something like a database table which is composed of a hash and equivalent url like this:
id: 1
hash: ABCDEF
realurl: http://site.tld/folders/videos/myvideo.mp4
Then, the video links are hidden by php like this:
http://site.tld/stream.php?video=ABCDEF
so that whenever I call the above url, it serves the file from realurl in database without the realurl being exposed to viewer since they are streaming the file/video through the stream.php
Any help would be appreciated.
EDIT: Here's what I did so far, still can't make it work. I wonder if I'm on the right way.
<?php
$video = $_GET['video'];
$username = "username";
$password = "xxxxxxxxxxx";
$hostname = "localhost";
$database = "stream";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db($database,$dbhandle)
or die("Could not select $database");
$path = mysql_query("SELECT `realurl` FROM `stream` WHERE `hash`=’$video")
or die(mysql_error());
readfile($path);
mysql_close($dbhandle);
?>
Your solution would work.
Assuming that your URLs will be permanent, make sure you backup your database so that in case of crash or data loss, you are able to re-point your dynamic URLs to the correct video files.
i hope this makes since so ill try my best to explain as much as i can
i have a personal server that i use for testing my scripts before i put them on my home page in my home page i have a script that uses a feed from a database on another server
how would i be able to get the contents from the off server to the server i am testing on can i do it like normal just change the urls?
e.g:
//Before//
$dbms = 'mysql';
$dbserver = 'localhost';
$dbport = '';
//after//
$dbms = 'mysql';
$dbserver = 'homesite.com';
$dbport = '21';
hope this makes since and if it has been answered before sorry just point me to right direction :)
Thanks
Rob
MySQL's usual port is 3306, so that not only needs to be forwarded through any router(s) there may be, but also allowed on any firewall(s). Further, the users themselves in MySQL need access, unless their host in the mysql.users table is set to %, which I don't recommend, however, instead have your IP and/or hostname (depending on MySQL's look up settings in my.ini), however if the IP address changes, you'll need to update this.
Some more info:
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html
I have a php script that limits the amount of times people can download content on my site. I found this script by google searching and changed it a bit to get it working for me.
The problem is I don't know anything really about php. The first part of the script checks the referring page. When I copied the php script, it was set up to check a single URL. My problem is I want to reference the php script from multiple pages, because one page has flash on it, and another page I created for mobile phones that don't have flash. Because of this, the link only works on one page - the page with the url I replace in the script.
My question is, what is the code to include multiple URLs in the reference check? I don't know if it's something very simple, or if it's even possible.
Below is the part of the php script which checks the referring URL, and then proceeds to login to mySQL DB to begin the download.
$referer = $_SERVER['HTTP_REFERER'];
$keymatch= $_SESSION['key'];
$pass='key';
$md5value= md5($pass);
if (($referer=="my url containing php script link")&& ($keymatch==$md5value)) {
$username = "user";
$password = "password";
$hostname = "host";
$database = "database";
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$selected = mysql_select_db($database,$dbhandle)
or die("Could not select $database");
Thanks in advance for any help.
-Richard
Rather than checking referer matches on one link:
if (($referer=="my url containing php script link")...
Create an array of links and match against that:
$referers = array('link1', 'link2','link3');
if((in_array($referer, $referers)...
I need to connect to another database in Joomla! that's on another server. This is for a plugin and I need to pull some data from a table.
Now what I don't want is to use this database to run Joomla!, I already have Joomla! installed and running on its own database on its server but I want to connect to another database (ON TOP of the current one) to pull some data, then disconnect from that 3rd party database - all while keeping the original Joomla database connection in tact.
You can connect to an external database from your joomla instance without using the current ressource of your joomla DB.
Try this:
<?php
$option = array(); //prevent problems
$option['driver'] = 'mysql';
$option['host'] = 'dbase.host.com';
$option['user'] = 'login';
$option['password'] = 'pwd';
$option['database'] = 'anotherdb';
$db = & JDatabase::getInstance( $option );
?>
For more infromations regarding this, check the Joomla! Documentation
I had same problem before. Fond a good tutorial showing how to connect to multiple database and switch back and forth, it also has sample code. It explains how to connect to multiple (internal and external) databases factory style, without creating multiple connections per request. This means that if you create database instance in controller same connection will be used in the model. Improves performance.
Another good explanation is on Joomla Documentation site [http://docs.joomla.org/How_to_connect_to_an_external_database].
Can you create a generic mysql-php conection inside your plugin code to create a connection ?
like
mysql_connect("remot_server_ip:3306","user","pass");
mysql_select_db("your database");
//code goes here
:
:
:
mysql_close(connection);